C compiler internals

G

Guru Jois

Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Bye
Guru Jois
 
J

Jensen Somers

Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Bye
Guru Jois

There are a lot of different C compilers out there and some of them are
closed source. I don't think the MSVC compiler has a lot of in-depth
documentation on how it works internally.

Take a look at the following link for some information about the GCC
compiler:
http://en.wikibooks.org/wiki/Category:GNU_C_Compiler_Internals

Hope it helps a bit.

Regards,
Jensen
 
C

Chris Dollin

Guru said:
Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Why?

I mean, what problem do you hope to solve with this information?

Compilers allocate memory -- and registers -- to variables in
ways that will make the code faster, or smaller, or the compiler
easier to write, or faster, or smaller; the tradeoffs differ
even between compilers for the same architecture and can often
be controlled by command-line switches; what are you going to
do with the answer?
 
S

Serve Laurijssen

Guru Jois said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

read books on compiler design maybe, although that has nothing to with C
anymore
 
J

jacob navia

Guru said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Bye
Guru Jois
Hi guru

How lcc-win32 allocates memory to variables
-------------------------------------------

For lcc-win32 there are several types of variables:
1) File scope variables, that are allocated in the initialized variables
section of the executable. For example:
int table[] = {1,2,3,4,5,6};
Lcc-win32 will reserve space in the data section for six 32 bit
numbers and initialize that to the binary values given.
Each object code file (.obj) can contain contributions to this
segment. The linker combines them all into a single segment.
2) File scope variables without any initial values. For example:
int table[6];
Lcc-win32 will reserve space for 6 32 bit numbers in the
uninitialized variable section (bss) and the value of them will be
set to zero when the system loads the program into memory.
3) Local variables.
They are allocated into a memory block reserved for temporary
storage. This is normally the stack segment. At entry of a function,
its activation record will be built, and the stack will be adjusted
to contain space for all local variables of the function. This
storage will be reclaimed when the function exits.

4) Variable length automatic variables
This variables will be allocated in the stack in a similar way as
(3) but they are not part of the activation frame since the
activation frame is fixed length, and this variables are variable
length. Example:
int fn(int n)
{ int table[n]; // <<<--- variable length array (VLA)
}
 
J

jacob navia

Guru said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Bye
Guru Jois
Hi guru

How lcc-win32 allocates memory to variables
-------------------------------------------

For lcc-win32 there are several types of variables:
1) File scope variables, that are allocated in the initialized variables
section of the executable. For example:
int table[] = {1,2,3,4,5,6};
Lcc-win32 will reserve space in the data section for six 32 bit
numbers and initialize that to the binary values given.
Each object code file (.obj) can contain contributions to this
segment. The linker combines them all into a single segment.
2) File scope variables without any initial values. For example:
int table[6];
Lcc-win32 will reserve space for 6 32 bit numbers in the
uninitialized variable section (bss) and the value of them will be
set to zero when the system loads the program into memory.
3) Local variables.
They are allocated into a memory block reserved for temporary
storage. This is normally the stack segment. At entry of a function,
its activation record will be built, and the stack will be adjusted
to contain space for all local variables of the function. This
storage will be reclaimed when the function exits.

4) Variable length automatic variables
This variables will be allocated in the stack in a similar way as
(3) but they are not part of the activation frame since the
activation frame is fixed length, and this variables are variable
length. Example:
int fn(int n)
{ int table[n]; // <<<--- variable length array (VLA)
}
 
J

jacob navia

Guru said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Bye
Guru Jois
Hi guru

How lcc-win32 allocates memory to variables
-------------------------------------------

For lcc-win32 there are several types of variables:
1) File scope variables, that are allocated in the initialized variables
section of the executable. For example:
int table[] = {1,2,3,4,5,6};
Lcc-win32 will reserve space in the data section for six 32 bit
numbers and initialize that to the binary values given.
Each object code file (.obj) can contain contributions to this
segment. The linker combines them all into a single segment.
2) File scope variables without any initial values. For example:
int table[6];
Lcc-win32 will reserve space for 6 32 bit numbers in the
uninitialized variable section (bss) and the value of them will be
set to zero when the system loads the program into memory.
3) Local variables.
They are allocated into a memory block reserved for temporary
storage. This is normally the stack segment. At entry of a function,
its activation record will be built, and the stack will be adjusted
to contain space for all local variables of the function. This
storage will be reclaimed when the function exits.

4) Variable length automatic variables
This variables will be allocated in the stack in a similar way as
(3) but they are not part of the activation frame since the
activation frame is fixed length, and this variables are variable
length. Example:
int fn(int n)
{ int table[n]; // <<<--- variable length array (VLA)
}
 
J

jacob navia

There is a bug in the thunderbird client apparently...
It sent the message three times

Sorry about this

jacob
 
T

Tor Rustad

Guru said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.


Try, comp.compilers and check their FAQ.
 
B

Barry Schwarz

Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Your posts indicate you are a relative newcomer to C and programming.
It is much too early for you to be jumping into a topic this complex.

Why do you care how one particular compiler allocates variables? It
may have nothing to do with how your compiler does so. It may change
completely in the next version of the compiler.

At this stage in your development, you should not be writing code that
depends on a particular allocation technique. Concentrate on the
portable features of the standard language, which is the area this
newsgroup deals with.


Remove del for email
 
D

Dave Vandervies

Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Take a look at the Dragon Book.

If that doesn't tell you what you're looking for, you could always
try Knuth.


dave
 
M

Malcolm McLean

Guru Jois said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.
If want the very basics about how to get into the compiler construction
game, read my book MiniBasic - how to write a script interpreter. It is an
interpreted rather than a compiled language, but the principles of variable
usage are similar, however interpreters are easier to write and understand
than compilers. It is only $2.50.

If you already know how to write a Basic, try the dragon book by Aho, Sethi
and Ullman. This is a much more advanced text.
 
G

Guru Jois

Your posts indicate you are a relative newcomer to C and programming.
It is much too early for you to be jumping into a topic this complex.

Why do you care how one particular compiler allocates variables? It
may have nothing to do with how your compiler does so. It may change
completely in the next version of the compiler.

At this stage in your development, you should not be writing code that
depends on a particular allocation technique. Concentrate on the
portable features of the standard language, which is the area this
newsgroup deals with.

Remove del for email

Yaeh, I am new to C, but I expect questions about compiler activities
in interviews. So I need docs.
Bye
Guru
 
C

Chris Hills

Guru said:
Hai,

Can I get some docs or links to learn the C compiler internals
from basic to advanced. It must contains good documentation of how
compilers allocates memory to variables.

Hi,

Compilers are in two parts the front end parser and the target specific
back end. Where the variables are put and how the memory is allocated
will depend on the target which is handled in the back end. It won't be
the same for an 8061 as a 68000 MCU. Some turn out assembler and some
object code.

I can send you a PDF book on compiler design but no book on compiler
design goes from basic to advanced. They go from advanced to very
advanced.

Then you have the assembler and linker do contend with

also books on compiler design are standard technology. Most commercial
compilers use many proprietary tricks and techniques.

The best place to start is probably GCC. You get the source and a lot of
people know how it works internally.

I would suggest that the way you have asked the question indicates that
you probably do not have the experience to delve into compiler design
just yet unless it is just for interest. Though I expect you will find
it very heavy going..
 
C

Chris Hills

Guru said:
Yaeh, I am new to C, but I expect questions about compiler activities
in interviews. So I need docs.
Bye
Guru

You will not get questions about compiler internals at interviews. If
you do you are applying for the wrong job.

What sort of jobs are you applying for?
 
C

Chris Hills

Guru said:
Yaeh, I am new to C,

The missing lines are:-

"I am Master of Computer Application graduate and currently studying
"Advanced C and Unix" course in Uttara, Bangalore, India."
 
D

David Wade

Guru Jois said:
Yaeh, I am new to C, but I expect questions about compiler activities
in interviews. So I need docs.
Bye
Guru

If you want to prepare for an interview have a look through the archived
copy of this newsgroup at groups.google.com. I would start by searching for
threads that contain "undefined behaviour". Most other documentation
concentrates on "how to do" something. These topics will help you understand
why some things don't work, and also how the compiler works...

I am pretty sure the information in here is more enlightening than any crib
sheet,,,,
 
K

Keith Thompson

David Wade said:
If you want to prepare for an interview have a look through the archived
copy of this newsgroup at groups.google.com. I would start by searching for
threads that contain "undefined behaviour". Most other documentation
concentrates on "how to do" something. These topics will help you understand
why some things don't work, and also how the compiler works...

You may need to search for both "undefined behaviour" and "undefined
behavior" (UK vs. US spelling); I'm not sure whether Google is smart
enough to translate automatically. It's sometimes also referred to as
"UB".
 
W

Walter Roberson

You may need to search for both "undefined behaviour" and "undefined
behavior" (UK vs. US spelling); I'm not sure whether Google is smart
enough to translate automatically. It's sometimes also referred to as
"UB".

Search also for nasal and demons (or daemons) ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top