By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,379 Members | 1,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,379 IT Pros & Developers. It's quick & easy.

C compiler internals

P: n/a
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

May 27 '07 #1
Share this Question
Share on Google+
18 Replies


P: n/a
On Sun, 27 May 2007 04:52:52 -0700, Guru Jois wrote:
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/Categor...iler_Internals

Hope it helps a bit.

Regards,
Jensen
May 27 '07 #2

P: n/a
Guru Jois wrote:
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?

--
Interpreting Hedgehog
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/

May 27 '07 #3

P: n/a

"Guru Jois" <gu*******@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
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
May 27 '07 #4

P: n/a
Guru Jois wrote:
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)
}
May 27 '07 #5

P: n/a
Guru Jois wrote:
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)
}
May 27 '07 #6

P: n/a
Guru Jois wrote:
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)
}
May 27 '07 #7

P: n/a
There is a bug in the thunderbird client apparently...
It sent the message three times

Sorry about this

jacob
May 27 '07 #8

P: n/a
Guru Jois wrote:
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.
--
Tor <torust [at] online [dot] no>
May 27 '07 #9

P: n/a
On 27 May 2007 04:52:52 -0700, Guru Jois <gu*******@gmail.comwrote:
>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
May 27 '07 #10

P: n/a
In article <11**********************@z28g2000prd.googlegroups .com>,
Guru Jois <gu*******@gmail.comwrote:
>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

--
Dave Vandervies dj******@csclub.uwaterloo.ca

Where should I turn in my certificate of infallibility?
--CBFalconer in comp.lang.c
May 27 '07 #11

P: n/a

"Guru Jois" <gu*******@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
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.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

May 28 '07 #12

P: n/a
On May 27, 11:46 pm, Barry Schwarz <schwa...@doezl.netwrote:
On 27 May 2007 04:52:52 -0700, Guru Jois <guru.j...@gmail.comwrote:
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
Yaeh, I am new to C, but I expect questions about compiler activities
in interviews. So I need docs.
Bye
Guru

May 28 '07 #13

P: n/a
In article <11**********************@z28g2000prd.googlegroups .com>, Guru
Jois <gu*******@gmail.comwrites
>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..
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 28 '07 #14

P: n/a
In article <11*********************@j4g2000prf.googlegroups.c om>, Guru
Jois <gu*******@gmail.comwrites
>On May 27, 11:46 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 27 May 2007 04:52:52 -0700, Guru Jois <guru.j...@gmail.comwrote:
>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

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?

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 28 '07 #15

P: n/a
In article <11*********************@j4g2000prf.googlegroups.c om>, Guru
Jois <gu*******@gmail.comwrites
>On May 27, 11:46 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 27 May 2007 04:52:52 -0700, Guru Jois <guru.j...@gmail.comwrote:
>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

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."
>but I expect questions about compiler activities
in interviews. So I need docs.
Bye
Guru
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 28 '07 #16

P: n/a

"Guru Jois" <gu*******@gmail.comwrote in message
news:11*********************@j4g2000prf.googlegrou ps.com...
On May 27, 11:46 pm, Barry Schwarz <schwa...@doezl.netwrote:
On 27 May 2007 04:52:52 -0700, Guru Jois <guru.j...@gmail.comwrote:
>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

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,,,,
May 28 '07 #17

P: n/a
"David Wade" <g8***@yahoo.comwrites:
[...]
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".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 28 '07 #18

P: n/a
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>"David Wade" <g8***@yahoo.comwrites:
>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".
>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) ;-)
--
Programming is what happens while you're busy making other plans.
May 28 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.