Mail Archives: djgpp/2004/03/23/05:46:11
>> pcampo=reg+ncampo+relativo*nc; // for example
> remember C address arithmetic works in units of t_field: multiplies
> ncampo+relativo*nc by sizeof t_field before adding to reg; are you
> sure you need to multiply relativo by nc here? you are adding relativo
> * nc t_field objects; how big is nc here?
Yes, I want to point to certain struct in a table. 'relativo' gets 1 or -1
to sum or rest the offset 'nc', that is a little value, between 3 and 1 in
this case. But the result of 'pcampo' is always grater than 'reg' (I will
put another assertion to ensure that, though I'm convinced this is not
failing)
>> if (pcampo>reg+MAXFIELDS) { // intercept huge (bad) values
> multiplies MAXFIELDS by sizeof t_field before adding to reg
Yes, I write that instead of "if ((int)(pcampo-reg)>MAXFIELDS)", it is
something natural for me. I use pointers all the time.
>> printf("Wrong field number: %d",(int)(pcampo-reg));
> divides the difference between the addresses by sizeof t_field
Yes, here I want to show the number of field in the table, not an address.
>> The problem is at the 'if'. It gave "Wrong field number: 14" but I can't
>> understand how can it be 14 pcampo-reg and go into de "if
>> (pcampo>reg+5000) ". I did solve it changing to "if (pcampo-
>> reg>MAXFIELDS)", but cannot understand de difference.
> should not be overflow, as scaled value of MAXFIELDS added should only
> be about 450000-480000, although using the subtraction ensures that
> the calculation works in units of t_field instead of bytes, so you're
> less likely to overflow; once again, maybe look at the value of nc to
> see if the earlier calculation of pcampo could have overflowed?
I don't know how. I'll put assertions for each operand. But I cannot
reproduce the problem so I don't know when I can have more information
about it.
>> If you think the definition of 't_field' could be important, here it is
>> (without translation).
>>
>> typedef struct { char *nombre; int tam;
>> char *def; int vdesp; int hdesp; char *buf; unsigned
>> adoptamoneda:1; #ifndef NOCACHEATR
>> BOOL sincacheatr;
>> int cacheatrlisto;
>> char *cacheatributos[NATRIBUTOSCACHEABLES];
>> #endif
>> } t_campo;
>>
>> NOCACHEATR is undefined
>> NATRIBUTOSCACHEABLES is something like 15
> sizeof t_field/t_campo should be between 90-96 bytes, depending on
> whether adoptamoneda and sincacheatr are compiled as byte sized or
> word sized
It is 88 bytes.
BOOL is typedef int.
NATRIBUTOSCACHEABLES is 13.
Thank you for your exhaustive answer.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
- Raw text -