Amol Mohite wrote:

> say I have a char *c pointing to an array of 10 bytes.
> 
> When i do (int *)c++ (increment before typecast -- forget the brackets for
> nw), and equate it t  an int *i then
> 
> *i will return 2nd to fifth bytes as integer. Is this correct ?

No. `(int *)++c' or `(int *)(c+1)' would do that. `(int *)c++' stores
the result before the increment occurs.

> And supose the typecase is beore the incerenent like so :
> ((int *)c)++ then *i will return 5th to 8th byes. is this correct ?

++((int *)c) will do that, but again `((int *)c)++' stores the result
before the increment occurs.

> aslo how is exception handling implemented ? Does the processor have
> exception registers ?

What sort of exception? Hardware exceptions (e.g. segfault) result in
the processor jumping to a defined location. The details depend upon
the particular type of processor.

> Also if I have allocated a struct liek :
> 
> struct {
>       int i;
>       char b;
> }str;
> 
> which is obviously 5 butes large.

1. The ANSI standard doesn't specify that `sizeof(int) == 4', so you
shouldn't assume that it is. If you want an integer of a specific
size, use the types from sys/types.h, e.g. int32_t.

2. It's 8 actually bytes on x86 using gcc. The structure is padded to
a whole number of words. If you wanted to pack the structure, use:

        struct {
                int i;
                char b;
        } __attribute__ ((packed)) str;

[NB: this is a gcc extension.]

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to