标签: standards

在哪里定义int()为0?

#include <iostream>
#include <string>

int main() {
    std::pair<std::string, int> s;
    std::cout << s.second << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

在这个例子s.second0虽然没有初始化.您能否提供C++标准的链接,其中定义了为什么0.我知道这是因为s.second被初始化了int(),但是无法找到标准中所说的那条int()线0.

c++ standards

0
推荐指数
2
解决办法
193
查看次数

EOF保证是-1吗?

用C语言编写代码时,使用-1EOF交替使用是否很好?标准保证EOF是这样的-1吗?或者是定义了价值实施?

例如,如果函数EOF在某些情况下返回,那么测试函数是否返回是否是一种好的样式-1

如果函数-1在某些情况下返回,那么测试函数是否返回是否是好的样式EOF

c standards language-implementation standards-compliance

0
推荐指数
1
解决办法
79
查看次数

ToList()查询之前的代码差异

这种方法有什么区别

public List<CollegeAddress> GetAllAddress()
{
    return collegeAppContext.CollegeAddresses.ToList().Where(x => x.StateId == 4);
}
Run Code Online (Sandbox Code Playgroud)

public List<CollegeAddress> GetAllAddress()
{
    return collegeAppContext.CollegeAddresses.Where(x => x.StateId == 4).ToList();
}  
Run Code Online (Sandbox Code Playgroud)

哪一种方法是标准代码?(但我的第一种方法扔了交谈错误:)

有什么区别?

c# comparison performance standards entity-framework

0
推荐指数
1
解决办法
62
查看次数

C中字符串文字的最大可能长度

C中字符串文字的最大可能长度是多少?如果我没有错,在Java和.NET中,最大可能的长度是2^31 - 1.

c standards

0
推荐指数
1
解决办法
87
查看次数

C++如何为这个"vector [0] = 1;"重载解析

据我所知,C++只有基于参数或implicate对象参数的函数重载.但我发现有两个operator []用于向量.它将在以下代码中选择正确的函数:

std::vector<int> v;
v[0] = 1; // This will select the non-const version.
return &v[0]; // This will select the const version.
Run Code Online (Sandbox Code Playgroud)

谁能解释这是怎么发生的?

      reference operator[] (size_type n);
const_reference operator[] (size_type n) const;
Run Code Online (Sandbox Code Playgroud)

------编辑1 ------

我认为它会选择const版本,因为下面的cc文件无法使用clang ++和g ++编译并出现以下错误.不明白以下错误.谁能解释更多?

错误:无法初始化'char*'类型的返回对象,其值为'const value_type*'(又名'const char*'),返回data_.size()== 0?NULL:(&data_ [0]);

#include <assert.h>

#include <deque>
#include <vector>
#include <map>


class X
{
public:

    X() {
    }

    virtual ~X() {
    }

    char* data() const {
        return data_.size() == 0 ? NULL : (&data_[0]);
    }

    size_t size() const {
        return …
Run Code Online (Sandbox Code Playgroud)

c++ standards

0
推荐指数
1
解决办法
115
查看次数

PHP严格标准:只应通过引用// array_pop传递变量

因为我在PHP 5.6中,所以我有这个警告(不是在PHP 5.2中):

PHP Strict Standards:  Only variables should be passed by reference in blockcategories_top.php on line 157
Run Code Online (Sandbox Code Playgroud)

这是第157行:

line 155    if ($cookie->last_visited_category) {
line 156      $c = new Category(intval($cookie->last_visited_category));
line 157      $oldies = array_pop($c->getParentsCategories());
line 158      $oldies = $oldies['id_category'];
line 159      $smarty->assign('oldies', $oldies);
line 160    }
Run Code Online (Sandbox Code Playgroud)

拜托,我该怎么办呢?:)

谢谢 !

php standards strict php-5.2 php-5.6

0
推荐指数
1
解决办法
2370
查看次数

使用realloc缩小内存分配

我想用来realloc从大块内存的末尾释放内存.我知道标准不要求realloc成功,即使请求的内存低于原始malloc/ calloc调用.我可以realloc,然后如果失败则返回原件吗?

// Create and fill thing1
custom_type *thing1 = calloc(big_number, sizeof(custom_type));
// ...

// Now only the beginning of thing1 is needed
assert(big_number > small_number);
custom_type *thing2 = realloc(thing1, sizeof(custom_type)*small_number);

// If all is right and just in the world, thing1 was resized in-place
// If not, but it could be copied elsewhere, this still works
if (thing2) return thing2;

// If thing2 could not be resized in-place and also …
Run Code Online (Sandbox Code Playgroud)

c malloc standards memory-management c99

0
推荐指数
1
解决办法
1221
查看次数

不应该将Postfix运算符视为二元运算符

后缀运算符采用int参数.关于为什么会有一个问题,似乎答案是:" 因为Bjarne Stroustrup这么说 "

我对这个答案感到不舒服.如果Bjarne Stroustrup需要一些东西来解决编译器的行为方式不同,为什么他不能只关闭运算符是否返回引用?它让我质疑:

  1. 为什么我不能这样做: foo++ 13;
  2. 为什么int参数默认为1
  3. 为什么这被认为是一元运算符,需要一个论证

c++ standards binary-operators unary-operator postfix-operator

0
推荐指数
1
解决办法
83
查看次数

传递给std :: runtime_error的ctor的字符串对象的生命周期是多少?

根据cppreferences,explicit runtime_error( const std::string& what_arg );不会复制what_arg的内容.

我可以安全地将临时字符串对象传递给std::runtime_error's ctor

例如:

std::string GetATempString(const char* msg)
{
    return { msg };
}

int main()
{
    try {
        throw std::runtime_error(GetATempString("Hello"));
    } catch (const std::runtime_error& e) 
    {
            e.what(); // Is it guaranteed that "Hello" would be returned safely?
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ standards exception object-lifetime c++11

0
推荐指数
1
解决办法
84
查看次数

为什么C中的嵌套函数是针对C标准的

C标准(ANSI [C89],C99,C11)中不允许嵌套函数(块作用域中的函数声明).

但我无法在C标准中找到它.

编辑:

为什么函数定义不能在函数定义中(复合语句)?

c standards

0
推荐指数
1
解决办法
292
查看次数