--- In [email protected], "thos_fernando" <[EMAIL PROTECTED]> wrote: > > Hello Nico ,Peter, > > Thanks for posting your views.I was going through a code > fragment. Later I checked the complete code and the usage was: > > typedef enum {False, True} boolean; > boolean PLL_lock; > > if(PLL_lock==True) > .... > which was as Nico's example. > > Could you help out with some more clarifications ? > Since PLL_lock is now being used as a variable , would this have a > memory size and how much would that be?
Every variable occupies some memory. How much depends on the operating system, the underlying hardware, the compiler used, and what compiler flags have been used. It may be that PLL_lock will use only one byte; it might be that it uses two bytes; and it might just as well happen that it takes up four bytes. But as mentioned, this is defined by your particular compiler's implementation. You can find out yourself using this code snippet: printf( "Size of PLL_lock is %d bytes.\n", sizeof PLL_lock); On some machines you might have to change this to: printf( "Size of PLL_lock is %ld bytes.\n", sizeof PLL_lock); This is but one typical example why you should ALWAYS turn on the highest level of warnings for your compiler when compiling any code. Quite often you will encounter some warning messages which look strangely (I often see this when compiling some source code under Linux where the program is actually run on a Solaris machine), but it's still better to have a few warnings too much than to miss out anything like the above issue which _may_ cause you trouble in the long run; such small mistakes in the printf() mask are extremely hard to discover if you don't compile (for example) with gcc -Wall -ansi -pedantic ... > Peter's example on typedef needs some clarification too : > He wrote : > " > typedef int i, *ip, (*vfi)(void); > > We can now use the typenames to declare objects... > > i my_int; > ip my_int_pointer; > " > My query is why this is interpreted as : > ip my_int_pointer; (my_int_pointer is pointer to integer ??) > and not : > *ip my_int_pointer; (my_int_pointer is integer ??) > Is this because of the ANSI C standard ? <snip> Yes. But let's look in detail how the above example looks like to the compiler. The line reads: typedef int i, *ip, (*vfi)(void); To the compiler this is the same as these lines: typedef int i; typedef int *ip; typedef int (*vfi) (void); Meaning that the line ip my_int_pointer; will translate to int * my_int_pointer; This is standard C syntax since the very first days of K&R C (Brian Kernighan and Dennis Ritchie, two of the three "inventors" of C and Unix). Regards, Nico
