用g ++ 4.1发出奇怪的警告 [英] weird warning with g++ 4.1

查看:45
本文介绍了用g ++ 4.1发出奇怪的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下程序无法使用g ++ 4.1.1编译:

=========================== ======================= ==

// $ Id $

// $来源$


#include< stdint.h>

#include< stdio.h>


typedef struct {uint32_t one_c; }图表;

#define as_chart(c)((chart){one_c:(c)})

#define ascii(x)as_chart((uint8_t)(x ))

#define CR 13

#define LF 10

static void wr_ch_unbuffered_dos(void){

静态图表const crlf [2] = {ascii(CR),ascii(LF)};

for(int i = 0; i< 2; i ++)

printf("%d \ n",crlf [i] .one_c);

}


int main(int argc,char * argv []){

printf("%d%s \ n",argc,argv [0]);

wr_ch_unbuffered_dos();

返回0;

}

========================= ========================= ==

cpp-struct.cc:在函数''void wr_ch_unbuffered_dos()' ':

cpp-struct.cc:14:警告:'const chart'初始化器周围缺少括号

cpp-struct.cc:14:警告:缺失''常量表'初始化器周围的大括号'

cpp-struct.cc:14:错误:无法转换''图表''初始化''uint32_t''

cpp-struct.cc:14:错误:初始化时无法将''chart''转换为'uint32_t''


坏线是

静态图表const crlf [2] = {ascii(CR),ascii(LF)};


我很漂亮确定这样的代码适用于g ++ 3.

我现在该怎么办?

谢谢!


$ g ++ --version

g ++(GCC)4.1.1 20060525(Red Hat 4.1.1-1)


-

Sam Steingold(关于Fedora Core发布的 http://www.podval.org/~sds ) 5(波尔多)
http://palestinefacts.org http://camera.org http://truepeace.org
http: //israelunderattack.slide.com http://dhimmi.com http://pmw.org.il

无纸化办公将成为现实无纸化马桶后不久。

解决方案

Id




//

来源

the following program does not compile with g++ 4.1.1:
================================================== ==
// $Id$
// $Source$

#include <stdint.h>
#include <stdio.h>

typedef struct { uint32_t one_c; } chart;
#define as_chart(c) ((chart){one_c:(c)})
#define ascii(x) as_chart((uint8_t)(x))
#define CR 13
#define LF 10

static void wr_ch_unbuffered_dos (void) {
static chart const crlf[2] = { ascii(CR), ascii(LF) };
for (int i = 0; i < 2; i++)
printf("%d\n",crlf[i].one_c);
}

int main (int argc, char *argv[]) {
printf("%d %s\n",argc,argv[0]);
wr_ch_unbuffered_dos();
return 0;
}
================================================== ==
cpp-struct.cc: In function ''void wr_ch_unbuffered_dos()'':
cpp-struct.cc:14: warning: missing braces around initializer for ''const chart''
cpp-struct.cc:14: warning: missing braces around initializer for ''const chart''
cpp-struct.cc:14: error: cannot convert ''chart'' to ''uint32_t'' in initialization
cpp-struct.cc:14: error: cannot convert ''chart'' to ''uint32_t'' in initialization

the bad line is
static chart const crlf[2] = { ascii(CR), ascii(LF) };

I am pretty sure code like this worked with g++ 3.
What do I do now?
Thanks!

$ g++ --version
g++ (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)

--
Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux)
http://palestinefacts.org http://camera.org http://truepeace.org
http://israelunderattack.slide.com http://dhimmi.com http://pmw.org.il
The paperless office will become a reality soon after the paperless toilet.

解决方案

Id



//


Source


这篇关于用g ++ 4.1发出奇怪的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆