Spiros Bousbouras said:
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.
Google for it... Or RTFM perhaps.
Perhaps he did Google for it. I did and the only match I
get is this thread. As for the manual does the GCC manual
explain the rationale for warnings ? As a matter of interest
does any compiler manual do that ?
Googling for the actual message, rather than for a paraphrase of it,
might have been more successful. The phrase "near initialization", as
it turns out, isn't a description of the problem, just of where in the
code the problem occurs. The OP managed to give us the piece of the
puzzle that mattered least.
In this case, though, it's likely that neither a Google search nor the
gcc documentation would have provided the explanation that's already
been given in this thread. The OP's error was not necessarily failing
to search elsewhere, it was failing to provide enough information,
specifically the *exact* code and warning message, copy-and-pasted.
(Ideally, he could also have mentioned that he had tried Google and
"info gcc" and not gotten an answer, but I'm not going to complain
about that. I like to see questions that are as complete as possible,
and I'll provide advice on how to ask good questions, but I'm not
going to insist that everyone must post perfect and complete questions
every time.)
As I said elsethread, I tried this code:
#define ROWS 3
#define COLUMNS 3
char recvedValues[ROWS][COLUMNS] = {'\0'};
with "gcc -Wall" and got this:
c.c:3: warning: missing braces around initializer
c.c:3: warning: (near initialization for 'recvedValues[0]')
gcc is asking for a fully braced initializer, even though it's not
necessary. That's an issue that's entirely appropriate for discussion
in comp.lang.c (and we've been discussing it in this thread).
So IMHO Mark Bluemel's response ("Google for it... Or RTFM perhaps.")
wasn't quite right -- but I'm not flaming him for that. We all make
mistakes, and the OP's question was answered.
Another thing I probably should have mentioned is that in an array
initializer with a single value, such as
... = {'\0'};
that value is not propagated to the other elements of the array.
You might expect this:
int arr[5] = { 42 };
to be equivalent to
int arr[5] = { 42, 42, 42, 42, 42 }; /* nope */
but in fact it's equivalent to this:
int arr[5] = { 42, 0, 0, 0, 0 };
Elements whose values aren't specified are set to zero. It doesn't
happen to matter for the OP's code, but since the initializer {'\0'}
does set all the elements to '\0', it would be easy to draw the wrong
conclusion. For this reason, I prefer the idiom ``{ 0 }''; it seems
slightly less misleading.
Finally, this is a good resource:
http://www.catb.org/~esr/faqs/smart-questions.html