Not all guys write new code.
As a professional you may need to do code maintenance and bug fixing
also.
There might be instances where some moron has written this kind of code.
Struct address +1 and so on.
So when you go through this sort of code you actually need to know what
the programmer tried to do there,
It is a bad coding practice but in real world you need to know the bad
things if you want to be good.
I will give you an example :
I was going through mplayer code. The code was doing some protocol
handling.
To get into the data part he did a base address + sizeof(header struct).
He was getting the data in
base address + 31
When I took the same code and used it somewhere else I was getting
base address + 32 and i was losing the first byte of data field..
He had pragma packing enabled and my compiler did not support pragma
packing and I spent an hour finding this problem as the code base was
huge.
So here in c-prog , we actually need to educate people about the
pitfalls of this kind of bad coding practice with examples.
They are asking because they don't know, it's as simple as that.
Best ,
-Saswat
On Tue, 2006-12-26 at 13:03 -0700, Victor A. Wagner Jr. wrote:
> At 01:39 2006-12-26, tamilselvan balan wrote:
>
>
> >
> > The structure Name always points to the first element of the
> > structure.
> >
> > Orgin + 0 == Orgin.ch it is True
> >
> > but Orgin +1, Orgin+2 not points to the next elements.
> > Why?
>
>
> you still haven't answered MY question.
> Why do you think you need to do this?
>
>
>
>
> > "Victor A. Wagner Jr." <[EMAIL PROTECTED]> wrote:
> >
> > At 19:38 2006-12-22, tamilselvan balan wrote:
> > Hi Friends,
> > Can any body tell me how to access the structure
> > elements without using the elements name.
>
>
>
> short answer: no.
> longer answer: portably? definitely not.
>
> now for my question. Why do you think you need to do this?
>
>
> >
>
> (e.g)
>
> typedef struct {
> char *ch;
> int id;
> float salary;
> } Base;
>
> Base orgin;
>
> orgin + 0 point to the first element of Base ( ch )
> orgin +1 point to second element of Base (id)
> orgin + 2 point to Third element of Base ( salary)
>
> Is it possible to access the elements like this , if yes
> please let me to know
>
> Thanks&Regards,
> Selvan.
>
> Send free SMS to your Friends on Mobile from your Yahoo!
> Messenger. Download Now!
> http://messenger.yahoo.com/download.php
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"
Send free SMS to your Friends on Mobile from your Yahoo!
Messenger. Download Now!
http://messenger.yahoo.com/download.php
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"