![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| set Ulimit data segment to Unlimited | terala_s | UNIX for Advanced & Expert Users | 1 | 12-22-2007 12:10 PM |
| Use of uninitialized value in join or string at arraydef.pl | praveen_b744 | Shell Programming and Scripting | 5 | 08-31-2007 11:09 AM |
| extract segment | mpang_ | Shell Programming and Scripting | 1 | 01-12-2007 01:33 AM |
| Segment Fault | zhshqzyc | High Level Programming | 9 | 04-07-2006 12:47 PM |
| Extract data segment using awk?? | apalex | Shell Programming and Scripting | 1 | 07-27-2004 07:13 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
bss(uninitialized data) segment allocation
Hi
1) Please go through the following code : char string2[12]; char string1[6]; main() { memcpy(string2,"SENDER ",12); strcpy(string1,"******"); printf("%s\n%s\n",string1,string2); } 2) and the output of size command for the executable is : 1904 + 415 + 18 = 2337 3) and the output is as expected ( gdb output ): Breakpoint 1, main () at test.c:5 5 memcpy(string2,"SENDER ",12); 2: string2 = '\000' <repeats 11 times> 1: string1 = "\000\000\000\000\000" (gdb) s 6 strcpy(string1,"******"); 2: string2 = "SENDER " 1: string1 = "\000\000\000\000\000" (gdb) s 7 printf("%s\n%s\n",string1,string2); 2: string2 = "\000ENDER " 1: string1 = "******" My question is in what order the global variables are stored in the memory. For the above example, from the output of size command 18 is the total size of the global variables and when the strcpy statement is executed, it is overwriting the first character of string2 with NULL in order to terminate string1 with NULL. So, how the variables got stored in memory? 1) Is string1 followed by string2? 2) Is string2 followed by string1? Could anybody help in this regard Thanks |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|