近初化是什么意思 [英] What does near intialization mean
问题描述
嗨
我使用了一行作为
char recvedValues [ROWS] [COLUMNS] = {''\ 0''};
我的代码中
。我收到一个警告,因为接近初始化
recvedValues [0]。
我正在使用gcc 3.4
任何人都可以解释其含义。
谢谢
Aditya
Aditya写道:
嗨
我使用的行为
char recvedValues [ROWS] [COLUMNS] = {' '\0''};
我的代码中的
。我收到一个警告,因为接近初始化
recvedValues [0]。
我正在使用gcc 3.4
任何人都可以解释其含义。
Google for it ...或者也许是RTFM。
Aditya< ad ***** *******@gmail.com写:
我使用的行为
char recvedValues [ROWS] [COLUMNS ] = {''\ 0''};
我的代码中的
。我收到一个警告,因为接近初始化
recvedValues [0]。
我正在使用gcc 3.4
任何人都可以解释其含义。
不是没有看到你没引用的实际消息。
我试过编译这个:
#define ROWS 3
#define COLUMNS 3
char recvedValues [ROWS] [COLUMNS] = {''\ 0' '};
,带有gcc -c -Wall c.c (gcc 4.1.3)并得到:
cc:3:警告:初始化程序周围缺少大括号
cc:3:警告:(接近初始化' 'recvedValues [0]'')
gcc建议你对每个
嵌套级别的对象都应该有一个大括号。例如,您可能改为写:
#define ROWS 3
#define COLUMNS 3
char recvedValues [ROWS] [专栏]
= {{''\''',''\''',''\ 0''},
{'' \\ 0'',''\'',''\ 0''},
{''\ 0'',''\''',''\\ \\ 0''}};
但这种语言实际上并不要求你提供所有
括号,或为每个提供一个值
初始化对象的元素。你为第一个元素指定了''\ 0'',
recvedValues [0] [0];其他的被隐式设置为零转换为
相应的类型。
实际上,这是:
{0}
可用作* any *类型的初始化器(但gcc会警告
)。
-
Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti .net / ~kst>
在圣地亚哥地区寻找软件开发工作。
我们必须做点什么。这是事情。因此,我们必须这样做。
- Antony Jay和Jonathan Lynn,是部长
11月12日,11日:上午51点,Mark Bluemel< mark_blue ... @ pobox.comwrote:
Aditya写道:
嗨
我使用的行为
char recvedValues [ROWS] [COLUMNS] = {''\ 0''};
在我的代码中。我收到一个警告,因为接近初始化
recvedValues [0]。
我正在使用gcc 3.4
任何人都可以解释其含义。
Google for it ...或者也许是RTFM。
为什么像你这样的人只能在问答小组上讨论
基本上告诉人们在提问时迷路?像你这样的人的心态可以为心理学家提供一个完整的
论文。
B2003
Hi
I am using a line of as
char recvedValues[ROWS][COLUMNS] = {''\0''};
in my code. I get a warning as near initialization for
recvedValues[0].
I am using gcc 3.4
Can anybody please explain the meaning.
Thanks
Aditya
Aditya wrote:Hi
I am using a line of as
char recvedValues[ROWS][COLUMNS] = {''\0''};
in my code. I get a warning as near initialization for
recvedValues[0].
I am using gcc 3.4
Can anybody please explain the meaning.Google for it... Or RTFM perhaps.
Aditya <ad************@gmail.comwrites:I am using a line of as
char recvedValues[ROWS][COLUMNS] = {''\0''};
in my code. I get a warning as near initialization for
recvedValues[0].
I am using gcc 3.4
Can anybody please explain the meaning.Not without seeing the actual message, which you didn''t quote.
I tried compiling this:
#define ROWS 3
#define COLUMNS 3
char recvedValues[ROWS][COLUMNS] = {''\0''};
with "gcc -c -Wall c.c" (gcc 4.1.3) and got:
c.c:3: warning: missing braces around initializer
c.c:3: warning: (near initialization for ''recvedValues[0]'')
gcc is suggesting that you should have a level of braces for each
nesting level of the object. For example, you might instead write:
#define ROWS 3
#define COLUMNS 3
char recvedValues[ROWS][COLUMNS]
= { { ''\0'', ''\0'', ''\0'' },
{ ''\0'', ''\0'', ''\0'' },
{ ''\0'', ''\0'', ''\0'' } };
But the language doens''t actually require you to provide all the
braces, or to provide a value for each element of the object being
initialized. You specified ''\0'' for the first element,
recvedValues[0][0]; the others are implicitly set to zero converted to
the appropriate type.
In fact, this:
{ 0 }
can be used as an initializer for *any* type (but gcc will warn about
it).
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@pobox.comwrote:Aditya wrote:Hi
I am using a line of as
char recvedValues[ROWS][COLUMNS] = {''\0''};
in my code. I get a warning as near initialization for
recvedValues[0].
I am using gcc 3.4
Can anybody please explain the meaning.
Google for it... Or RTFM perhaps.Why do people like you sit on a question and answer group only to
basically tell people to get lost when they ask a question? The
mentality of people like you could provide a psychologist with a whole
thesis.
B2003
这篇关于近初化是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!