What does near intialization mean

A

Aditya

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
 
M

Mark Bluemel

Aditya said:
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.
 
K

Keith Thompson

Aditya said:
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).
 
B

Boltar

Aditya said:
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
 
R

Richard Heathfield

Keith Thompson said:

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).
 
C

Chris Dollin

Boltar said:
Aditya said:
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.
 
B

Boltar

Boltar said:
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
 
C

Chris Dollin

Boltar said:
Boltar said:
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.
 
R

Richard Heathfield

Boltar said:
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.
 
B

Boltar

Chris said:
* 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
 
D

dj3vande

If a newsgroup dedicated to C isn't an online community I'm not sure
what is.

So comp.lang.c is an online community, and therefore you shouldn't
bother to do something that helps both you and CLC? You might want to
review your logic there.

The days of 9600 baud modems being clogged up downloading posts have
thankfully departed.

Yes. That means it's now trivial to download more news articles than
anybody has the time or energy to read and reply to. How, exactly,
does this give us more resources to waste on answering simple questions
that you'd find your answer to more quickly and more easily in a
reference manual?

This isn't school, showing willing is irrelevant.

Most people are rather more likely to put time and energy into offering
help if it looks like that help will have some benefit. Demonstrating
that you're unwilling to put any energy into it on your side is a
pretty good clue that it's not worth our resources either.

3 not very good ones.

*plonk*



dave
 
F

Flash Gordon

Boltar wrote, On 12/11/07 20:13:
If a newsgroup dedicated to C isn't an online community I'm not sure
what is.

Yes, so researching things yourself will help you and this community.
The days of 9600 baud modems being clogged up downloading posts have
thankfully departed.

Irrelevant. The important resource is the people and their time, and
that is limited.
This isn't school, showing willing is irrelevant.

Yes, it isn't a school so we are not being paid to teach you.
3 not very good ones.

No, three good reasons if you took the time to understand them.

A forth good reason is that you are more likely to get help from the
most knowledgeable if you put in some effort yourself.
 
B

Boltar

So comp.lang.c is an online community, and therefore you shouldn't
bother to do something that helps both you and CLC? You might want to
review your logic there.

The guy was just asking a question. Isn't that the whole point of
these groups? Or are they just old boys clubs where the incumbents
just look down their nose at the newbies and fire of sarcastic
potshots?
anybody has the time or energy to read and reply to. How, exactly,
does this give us more resources to waste on answering simple questions
that you'd find your answer to more quickly and more easily in a
reference manual?

Thats the point of subject lines. You read what you find interesting.
Its a useful concept, try it out sometime.

#include <stdeasywayoutoflosingtheargument.h>

B2003
 
B

Boltar

Irrelevant. The important resource is the people and their time, and
that is limited.

Don't talk such rubbish. If people had work to do they wouldn't be on
here browsing the posts in the first place.
Yes, it isn't a school so we are not being paid to teach you.

Not are you being paid to post non-replies. If you have nothing to
say , say nothing.

B2003
 
R

Richard Heathfield

Boltar said:

The guy was just asking a question. Isn't that the whole point of
these groups?

No. The Q&A aspect of newsgroups is incidental to their original purpose,
which was to exchange and discuss *news* - hence the name "newsgroup".
Nevertheless, the Q&A serves a useful purpose - that of stimulating
informative discussion - and so it is not only tolerated but encouraged.
But it is certainly not the whole point of the groups.

<snip>
 
R

Richard Heathfield

Boltar said:
Don't talk such rubbish. If people had work to do they wouldn't be on
here browsing the posts in the first place.


Not are you being paid to post non-replies. If you have nothing to
say , say nothing.

Physician, heal thyself. So far, you have had nothing whatsoever to say
about C in this thread or in any other recent thread. Indeed, a Web search
of Google's archives reveals only two articles from you that were posted
before today, both on January 5th, one of which contains an incorrect
claim about C and the other of which contains an acknowledgement that the
claim was incorrect.

If you have nothing to say...
 
M

Mark McIntyre

Boltar said:
Boltar said:
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?

Says anybody with gumption. If you want to know how to programme your
DVD recorder, do you ask in the pub, or read the manual?

Naturally however its easier for the Now generation just to fire off a
demand into the internet, and complain when they don't get sensible or
correct answers.
 
M

Mark McIntyre

Boltar said:
This isn't school, showing willing is irrelevant.

No, its real life. Being sociable is rewarded. Being petulant and lazy
is dealt with accordingly.
 
M

Mark McIntyre

Aditya said:
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].


You get a warning that the error is near the place where you initialise
recvedValues[]. Hence it is "near initialisation for..."
 
P

Peter Nilsson

Richard Heathfield said:
Keith Thompson said:

Yes, and I dearly wish it wouldn't. The construct is well-
defined,
True.

well-known,

Debatable (though I won't ;-)
and idiomatic.

The author of the warning probably went to the Heathfield
school of C and took the adage 'all variables must be
explicitly initialised' a bit too literally. :)
To warn against it is ludicrous (but of course
perfectly legal).

Note that (*s++ = *d++) is no less well defined, well-known,
and idiomatic, but it is also given a warning by gcc.

Yet another reason not to get pre-occupied with warnings,
or 'style' as measure of correctness (or incorrectness.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top