473,797 Members | 3,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does near intialization mean

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

Nov 12 '07 #1
65 3616
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.
Nov 12 '07 #2
Aditya <ad************ @gmail.comwrite s:
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_Keit h) 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"
Nov 12 '07 #3
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@p obox.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

Nov 12 '07 #4
Keith Thompson said:

<snip>
In fact, this:
{ 0 }
can be used as an initializer for *any* type (but gcc will warn about
it).
Yes, and I dearly wish it wouldn't. The construct is well-defined,
well-known, and idiomatic. To warn against it is ludicrous (but of course
perfectly legal).

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 12 '07 #5
Boltar wrote:
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@p obox.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?
Because newsgroups shouldn't be the /first/ port-of-call when
one needs a question answered?
The mentality of people like you could provide a psychologist with
a whole thesis.
/Anyone's/ mentality would provide material for a thousand theses.

--
Chris "'perverse' doesn't mean 'complex'" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Nov 12 '07 #6
On Nov 12, 2:58 pm, Chris Dollin <chris.dol...@h p.comwrote:
Boltar wrote:
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@p obox.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?

Because newsgroups shouldn't be the /first/ port-of-call when
one needs a question answered?
Says who?

B2003
Nov 12 '07 #7
Boltar wrote:
On Nov 12, 2:58 pm, Chris Dollin <chris.dol...@h p.comwrote:
>Boltar wrote:
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@p obox.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?

Because newsgroups shouldn't be the /first/ port-of-call when
one needs a question answered?

Says who?
I do, for two reasons:

* people learning to find things out for themselves using the search
tools available helps them and the communities they partake in.

* people answering the simpler questions for themselves means that
newsgroups have more resources available for answering the
/complicated/ questions.

* being able to support a question with "I tried looking for X and
only got Y" or "I tried X and got different mysterious result Z"
shows willing and provides extra context and evidence for an answer.

OK, so that's three reasons.

--
Chris "colour me countless" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 12 '07 #8
Boltar said:
On Nov 12, 2:58 pm, Chris Dollin <chris.dol...@h p.comwrote:
>Boltar wrote:
On Nov 12, 11:51 am, Mark Bluemel <mark_blue...@p obox.comwrote:
<snip>
>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?

Because newsgroups shouldn't be the /first/ port-of-call when
one needs a question answered?

Says who?
Says common sense. More about that in a second, though. Let's first deal
with the anti-authority thing. In a sense, you're right - very few[1]
people can *stop* anyone from posting anything they like here, and in a
way that's a good thing, because nobody likes censorship.

So if it's a question of "I'll post what I like and nobody's gonna stop me,
so there", well, so be it. But those who seek help need to remember that
nobody here is required to help them, and nobody here gets paid for
helping them. So, if they want to attract help, the best way to do it is
to ask for help in a way that attracts that help, rather than repelling
it.

Let me give you a concrete example of that. A few moments ago, I read a
request for C help from someone who has, in the past, habitually acted in
a very offensive way towards those who freely provide expert assistance in
this newsgroup. It is very likely that I could have helped him to get over
his problem quickly and efficiently (although it would have required his
offering more information), but I chose not to bother, because of his
previous posting behaviour, which I don't wish to encourage.

So... why is it a good idea to look for an answer on the Web or in
textbooks rather than in newsgroups? Why is that considered a sensible
first step in one's quest for knowledge? And the answer is very simple:
people's time is limited. Web servers will happily send out pages of
information all day long, but people have other stuff to do. So it makes
sense to seek your answer from time-inexpensive sources such as Web sites
or books *first*. The chances are good that you'll get your answer this
way.

None of the regular contributors to this newsgroup has universal knowledge
of all things; we all come across problems of our own. But in general we
don't bother asking for help here (or indeed in other groups) because,
99.9% of the time, the answer is there for the finding, on a Web site or
in a book. On the very few occasions that one of comp.lang.c's regular
contributors asks for help, it is because he or she has already checked
what he or she considers to be the usual sources of information, and has
drawn a blank there. At *that* point, it is not unreasonable to ask
someone else to spend their time helping the questioner. (Equally, it is
not unreasonable of them to decide not to do that. Their time is their
own.)

So, as a matter of courtesy, it makes sense to seek your answer from other
sources first, and to use this newsgroup as a backstop. (Indeed, that's
why we have an FAQ list - to move some of the common questions offline, so
to speak.)

Can you ignore the courtesies and just plough straight in with your
question, not bothering to do any research yourself? Of course you can -
but equally, the regular contributors to the group can ignore *you* if
they choose. It's up to each of us to use other people's time, and our
own, responsibly.
[1] I say "very few" because there are bound to be exceptions - e.g. maybe
there's an authoritarian regime/company/dad that censors Usenet articles
on servers (or indeed clients) over which it/he has legal jurisdiction. Or
think up your own example.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 12 '07 #9

Chris Dollin wrote:
* people learning to find things out for themselves using the search
tools available helps them and the communities they partake in.
If a newsgroup dedicated to C isn't an online community I'm not sure
what is.
>
* people answering the simpler questions for themselves means that
newsgroups have more resources available for answering the
/complicated/ questions.
The days of 9600 baud modems being clogged up downloading posts have
thankfully departed.
>
* being able to support a question with "I tried looking for X and
only got Y" or "I tried X and got different mysterious result Z"
shows willing and provides extra context and evidence for an answer.
This isn't school, showing willing is irrelevant.
>
OK, so that's three reasons.
3 not very good ones.

B2003

Nov 12 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.