Hi, Thanks for your quick response.
On 9 October 2012 13:39, <d...@gnu.org> wrote: > Viresh Kumar wrote: >> When we have following declaration: >> >> struct foo { >> char array[5]; >> .... >> }; >> >> And have a definition like: >> >> struct foo foo_abc = { >> .array = "12345", >> }; >> >> Problem here is: size of array is 5 bytes and so we can actually add a >> string with four characters only to it, as '\0' will take >> an additional space. >> >> But with my definition of foo_abc.. i had 5 characters + '\0'... that >> will make it 6 and that will overflow the array.. >> >> What will actually happen here? >> - compiler will not add '\0' at all? >> - or it will go outside of boundaries of array? > > I think it will go outside of boundaries. You should avoid adding the \0 or > redefine char array to hold up to 6 chars. Ok. So it will overwrite whatever follows the memory of this struct if array is the last element in this struct. > struct foo { > .... > char array[5]; > }; I am not adding '\0' in my string at all. Is this '\0' always added by compiler, even in above situation? -- viresh _______________________________________________ linaro-toolchain mailing list linaro-toolchain@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-toolchain