W
Wat
Is
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
?
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
?
Wat said:
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
S.Tobias said:Wat said:char a[100] = "";the same as,char a[100];
a[0] = '\0';
If `a' is a static object - yes (sort of, static objects are automatically
initialized to zero).
Wat said:Is
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
?
Stephen Mayes said:S.Tobias said:Wat said:char a[100] = "";the same as,char a[100];
a[0] = '\0';
If `a' is a static object - yes (sort of, static objects are automatically
initialized to zero).
Is this mandated by the standard?
Stephen said:char a[100] = "";the same as,char a[100];
a[0] = '\0';
If `a' is a static object - yes (sort of, static objects are automatically
initialized to zero).
Is this mandated by the standard?
That completely depends on whether they are static or not.Andrey Tarasevich said:Wat said:Is
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
?
No. The former initializes the whole array with zeroes. The latter sets
the first element to zero, but the rest remains unchanged.
--
Is this mandated by the standard?
Yes.
I have a free compiler ( I won't name ) that creates PE format executables.
When I don't initialize a static array, it lists the data in a .bss header,
so I have always assumed that the data was uninitialized.
Xenos said:That completely depends on whether they are static or not.Wat said:Is
char a[100] = "";
the same as,
char a[100];
a[0] = '\0';
?
No. The former initializes the whole array with zeroes. The latter sets
the first element to zero, but the rest remains unchanged.
--
...
BSS is a term from some early systems where it stood for "Blank Storage
Section" (or something similar).
Where it does often matter still is with embedded systems, where the
various link sections can be put into different types of memory (code
and constant data into ROM, initialised data into ROM which is then
copied to RAM, BSS just in RAM and set to zero by the start code, etc.)
Historical note: the name BSS comes from an IBM assembler, where it
stands for "Block Started by Symbol". The same assembler also had
a BES directive for "Block Ended by Symbol". (The Fortran compiler
used BES to create arrays, as the hardware had a peculiar manner of
doing array indexing in which A(1) had the highest address, A(2) had
a next-lower address, and so on -- the index was treated as if it
were negative.)
Modern linkers are even fancier, and can put specific (named)
sections in specific orders and regions and so on. Of course,
actually *using* any of this requires going beyond Standard C --
and one then discovers that each different linker for each system
does something slightly different. So if you can accomplish what
you need to do in "pure" Standard C, it saves a lot of effort.
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.