On 1 Sep, [EMAIL PROTECTED] wrote:
> #ifndef offsetof
> #define offsetof(s,m) (size_t)&(((s *)0)->m)
> #endif
>
> The problem is that I have tree fields... so, can I use this.? I'm not
> into math u know.
This isn't math, it's the C preprocessor and one C
addressing trick.
> This is my struct:
> typedef struct{
> char field1[20];
> char filed2[14];
> char field3[14];
> }dbRecord;
> tagg = FldGetTextPtr(GetObjectPtr(EditTaggField));
> DmWrite(nyScanrecord, offsetof(dbRecord, tagg),14); // Got undefine
Right, because "tagg" isn't a member of dbRecord. The macro
wants "s" to be a structure type, and m to be a member of
that structure.
Try
DmWrite(nyScanrecord, offsetof(dbRecord, field2), 14);
which may or may not have the effect you wanted.
Expand the macro yourself to see the code that your example
creates, and I think you'll see why it doesn't compile.
The only "trick" is using a zero-valued pointer ((s *)0) to
determine the address of a member of a structure at memory
location zero, which produces the member offset.
Good luck!
Dennis Rockwell [EMAIL PROTECTED]
BBN Technologies
GTE Technology Organization +1-617-873-5745
Cambridge, MA +1-617-873-6091 (Fax)