警告由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 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 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.为什么变量初始化?