Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
XML
Hi guys, I use g cc. I want to know the address of each and every line of code.Is there any way obtaining it through dis assembling? the first column of dis assembled output seems like address to me, but I am not sure.

    #include <stdio.h>
    #include <string.h>

    int main()
    {
        char name[20],address[500];
        printf("enter your name::: \n");
        fgets(name, sizeof(name), stdin);
        printf("name you entered is:: %s \n", name);
        printf("enter your name::: \n");
        fgets(address, sizeof(address), stdin);
        printf("address you entered is:: %s \n", address);
    }
for above example I want to know address at each and every line.
Posted
Comments
Richard MacCutchan 14-Jul-14 14:01pm    
You can get the relative address of each line from the assembler output, but that does not correspond exactly to the absolute (virtual) address when the program runs. In general this information is of little use to the average developer.

1 solution

The address of a piece of code is usually determined by the linker, not the compiler. What you see in an assembler code listing is a procedure relative address. The linker will combine the code from the various compilation units and then construct the executable or dll. And even in the moment when a dll is loaded, it might be relocated to a different address if a conflict with other dlls exists.

If you look at the disassembled code at runtime, for example in a debugger, then you might in fact see the final addresses where your code is located.

But be warned, when optimizing the code the compiler takes the freedom to mix instruction from various code lines. A single line of code might be spread over a large part of the code and interspersed with the code of other lines .
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Jul-14 14:05pm    
Right, a 5.
—SA
nv3 14-Jul-14 17:20pm    
Thank you, Sergey!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900