[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Some newbee questions :)

From: Bernard Fouche
Subject: RE: [avr-gcc-list] Some newbee questions :)
Date: Mon, 22 Nov 2004 11:46:23 +0100

I'm no expert, but IMHO:

> - for the variable pointer such as: char *code, how much byte does it
allocated in the memory (RAM)?

>From zero to two. Since the address space is 16bits (I dunno how the
atmega128 manages the upper 64K of flash), you point anywhere with 16 bits.
Now at compilation time your "char *code", if it is a local variable, can be
optimized to zero bytes because most of local variables are mirrored in MCU
registers. So "char *code" has a different memory footprint depending of the
way it is used.

>- the function:
>       char *strchr (const char *src, int val)
>  is used to find a certain character in the string memory , right?
>  then why it use int val instead of char val, because the charcater we're
>  looking for is a char variable?

In C, all 'char' are passed as 'int' when calling a function. If you call
strchr with a 'char' as second argument, then before the function is called,
this char will be changed to 'int'. Also if you write a function that
expects a char it will gets an int and use only the lower byte. So there is
no overhead cost to use an int of char, or, more exactly, the price has been
decided by K&R a long time ago, maybe because of the way their computers
were working (they could have word aligned CPU for instance and then the
cost of using ints is the same or lower than using chars). Now if you look
at all the stdio lib, you'll see that 'c', the character to process, is an
int. That allows for instance 'EOF' to be of a value different than the
chars to process.

> - is there a way to make a pointer in the RAM that point a certain
>  location in the program memory. lets say that i have a buffer of data to

The purpose of pointers is to point where you want :-) You can force a
pointer to point at any particular address, as you can make it to point to
anything that is designed by a name in C (variable or function) but macros
(macros are expanded at compile time).

>- and last question, where i can find out how the AVR gcc compiler works?
>  is there any complete reference i could find in the internet?

Avr-gcc is based on gcc, so you'll get all documentation on gcc on
http://gcc.gnu.org . Now you should also read the documentation about
avr-libc, it is bundled with the library source. If you're new to C/GCC,
looking at the library source code will be an excellent tutorial since
you'll learn how things can be done, how they are done, the library is small
compared to a full libc under linux for instance and is not too much
polluted with conditional compilation, so it's rather easy to understand how
it works.


avr-gcc-list mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]