The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 04-24-2005
karimulla_sha karimulla_sha is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 2
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0