B
ben
is there anyway in c to write code that can variably make use of one of
two structs (one that has 32 bit vals and the other that has 64 bit
vals) throughout the code? i'm writing some code that parses some data.
there's a few data types whose max values are 10^10 which requires 34
bits, so a u_int64_t type of variable would be needed to hold them
while using/manipulating. (as i write this the more i think about it
the more i think what i'm hoping for isn't on at all and the answer is
no but anyway..). nearly always, or even always (just with the tiny,
tiny, incredably remote chance they won't) the values in question will
fit into 32 bit values fine. on a 32 bit machine dealing with 64 bit
values throughout the code is going to slow things up i think, so what
i'm wondering is, is there anyway to variably use 32 bit values and 64
bit values somehow? the only way i can think of is just having pretty
much all the code duplicated, once for 32 bit handling and once for 64
bit handling. what i would like to do is set up two structs (one for 32
bit vals the other for 64) then based on an if statement at the start
of the code that determines which should be used, use that struct
throughout. at the end of the day the only way to do that is
duplication of the code that deals with the structs right? i just
thought i'd check in case there is some nifty way to get something like
this that i don't know about.
unions aren't any direct use. function pointers could be of use but
doesn't get round the problem of having to duplicate most, probably
nearly all, of the code. so i guess just use 64 bit vals and be done
with it. does seem a shame though because the real need for over 32 bit
values will be so rare -- although who knows in the future.
two structs (one that has 32 bit vals and the other that has 64 bit
vals) throughout the code? i'm writing some code that parses some data.
there's a few data types whose max values are 10^10 which requires 34
bits, so a u_int64_t type of variable would be needed to hold them
while using/manipulating. (as i write this the more i think about it
the more i think what i'm hoping for isn't on at all and the answer is
no but anyway..). nearly always, or even always (just with the tiny,
tiny, incredably remote chance they won't) the values in question will
fit into 32 bit values fine. on a 32 bit machine dealing with 64 bit
values throughout the code is going to slow things up i think, so what
i'm wondering is, is there anyway to variably use 32 bit values and 64
bit values somehow? the only way i can think of is just having pretty
much all the code duplicated, once for 32 bit handling and once for 64
bit handling. what i would like to do is set up two structs (one for 32
bit vals the other for 64) then based on an if statement at the start
of the code that determines which should be used, use that struct
throughout. at the end of the day the only way to do that is
duplication of the code that deals with the structs right? i just
thought i'd check in case there is some nifty way to get something like
this that i don't know about.
unions aren't any direct use. function pointers could be of use but
doesn't get round the problem of having to duplicate most, probably
nearly all, of the code. so i guess just use 64 bit vals and be done
with it. does seem a shame though because the real need for over 32 bit
values will be so rare -- although who knows in the future.