相关疑难解决方法(0)

如何修复警告:初始化器周围缺少括号?

警告由vala生成的c代码生成.

警告:初始化程序周围缺少大括号

代码有效但警告很烦人.警告引用的vala代码是

struct Position {uint x; uint y;}
private static Position positions[8];
Run Code Online (Sandbox Code Playgroud)

生成的C代码是

static Position det_positions[8] = {0};
Run Code Online (Sandbox Code Playgroud)

我已经尝试了六种不同方式初始化位置,但似乎无法获得满足警告的语法.这是GCC的错误53119还是有办法解决它?

gcc vala

42
推荐指数
2
解决办法
8万
查看次数

初始化时真的需要大括号吗?

根据GCC 4.6.3(Ubuntu/Linaro 4.6.3-1ubuntu5),我在以下代码中的数组初始化中缺少大括号:

#include <iostream>
#include <boost/array.hpp>
#include <array>

int main(){
  int                   plain[]   = {1,2,3,4,5};
  std::array  <int, 5>  std_arr   = {1,2,3,4,5}; // warning, see below
  boost::array<int, 5>  boost_arr = {1,2,3,4,5}; // warning, see below
  std::cout << plain[0] << std_arr[1] << boost_arr[2] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
> g++ test.cc -Wall -Wextra -pedantic --std=c++0x                                                                                  
test.cc: in function »int main()«:
test.cc:7:47: warning: curly braces missing around initialization for »std::array::value_type [5] {aka int [5]}« [-Wmissing-braces]
test.cc:8:47: warning: curly braces missing around initialization for »int [5]« [-Wmissing-braces] …

c++ gcc-warning

6
推荐指数
1
解决办法
1129
查看次数

非静态变量初始化

我正在读一本关于C progaming faq的书.这是本书的篇章

自动变量是在没有static关键字的函数或代码块内定义的变量.如果未显式初始化这些变量,则这些变量具有未定义的值.如果未初始化自动变量,则必须确保在使用该值之前将其分配给它.

这是我的代码:

#include <stdio.h>
int main (int argc, const char * argv[])
{    
    {
        int x;
        printf("%d", x);
    }
}
Run Code Online (Sandbox Code Playgroud)

结果printf为0.为什么变量初始化?

c

2
推荐指数
1
解决办法
4722
查看次数

标签 统计

c ×1

c++ ×1

gcc ×1

gcc-warning ×1

vala ×1