How is stack map

This is a discussion on How is stack map within the C Programming forums, part of the General Programming Boards category; Dear All, Code: #include<stdio.h> #define MAX_STR1_LEN 15 #define MAX_STR2_LEN 16 void main() { char a,b,c,d,e,f,g,h,j,k,l,m,n,o,count; char i=4; char str2[MAX_STR2_LEN]="0123456789abcdef"; chat ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    33

    How is stack map

    Dear All,
    Code:
    #include<stdio.h>
    #define MAX_STR1_LEN 15
    #define MAX_STR2_LEN 16
    void main()
    {
        char a,b,c,d,e,f,g,h,j,k,l,m,n,o,count;
        char i=4;
        char str2[MAX_STR2_LEN]="0123456789abcdef";
        chat str1[MAX_STR1_LEN]="0123456789abcde";
        str2[MAX_STR2_LEN]=0;
        str1[MAX_STR1_LEN]=0;
        printf("1.str1:%s  str2:%s\n",str1,str2);
        strcpy(str1,str2);
       printf("2.str1:%s str2:%s\n",str1,str2);
       for(count=0;count<i;count++);
       str2[MAX_STR2_LEN]='a';
       str1[MAX_STR1_LEN]=0;
       strcpy(str1,str2);
       printf("3. str1:%s str2:%s\n", str1,str2);
       for(; count<i;count++);
       printf("4. count:%d\n",count);
       return;
    }
    Stack map for above code is as the below from the high address to the low address:

    High:a b c d e f g h j k l m n o c i
    str2: 0 1 2 3 4 5 6 7 8 9 a b c d e f
    str1: 0 1 2 3 4 5 6 7 8 9 a b c d e x
    low: x x x x x x x..........

    my doubt is "How high address will get a b c d e f g h j k l m n.........weather these values are declared values or what"

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    I have absolutely no idea what you're asking.

    Your code has issues. You've got two for() loops that doesn't do anything at all, it's int main(), not void main(). Both of your strings are too small to hold the string literals you initialize them with, and you promptly overstep the end of the arrays immediately afterwards. I believe your strcpy() is also doomed. If your program compiles, I rather doubt it'll make it through execution. (No pun intended.)

    Edit: Alright, I can't help myself... "My program dies when I execute it" would be the perfect thread opener.
    Last edited by Cactus_Hugger; 08-16-2007 at 11:04 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Posts
    311
    Stack implementation isn't a question for C, but rather a question for the architecture of the machine you're programming on.
    GCC on Fedora Core 10

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    We did this already
    How i will get this output

    If you really want to map the addresses of all the local variables, do something like
    printf( "a is at %p\n", (void*)&a );

    And stop trying to analyse undefined behaviour because it isn't going to make you a better programmer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Quote Originally Posted by Shidlingayya View Post
    Dear All,

    <code snippet removed>

    Stack map for above code is as the below from the high address to the low address:

    High:a b c d e f g h j k l m n o c i
    str2: 0 1 2 3 4 5 6 7 8 9 a b c d e f
    str1: 0 1 2 3 4 5 6 7 8 9 a b c d e x
    low: x x x x x x x..........

    my doubt is "How high address will get a b c d e f g h j k l m n.........weather these values are declared values or what"
    1. Don't friggin duplicate post!
    2. Don't ever use the word 'doubt' if English is not your first language. Use the word 'question' instead. I'm not explaining this again today. It is just easier for all if you never touch the word 'doubt'. Forget it ever existed.
    3. Your question lacks a question mark.
    4. You means 'whether', not 'weather'. I don't care whether it's snowing or sweltering where you are.
    5. The program is full of bugs and undefined behaviour. There is no right answer when UB is involved.
    6. "void main" is not valid C code!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 09:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21