c - What is the systematic way when I want my code (client and server ) work on various scenarios? -
i developed in on 64-bit mac. , wish work under 2 scenarios:
64 bit server , 64 bit client
32 bit server , 64 bit client
only dealing *nix now
between communication of server , client b, exchange linked list of struct, of following type:
typedef struct a{ unsigned long filed1; int filed2; char filed3; struct a* next; } a_t
both size of char
, int
consistent between 32-bit , 64-bit machine. concern more pointer , unsigned long.
my sending/receiving strategy is:
send , receive array of list_size * sizeof(a_t)
bytes, since sizeof(a_t) have different values on 32-bit , 64-bit, array have misalignment. , wonder universal way fix problems of kind.
you should communicate in universal way independent of machine (both word size , endianness). easiest way send ascii, example, csv, in order of list. receiver can generate list this.
in principle should write irs, interface requirements specification, contract between 2 parties. should deal order of records, formats , (for example) minimum/maximum of numeric fields can be. practice write down, how minimal , if contract yourself. add comment in relevant functions on server side , on client side. programmer having deal in future knows constraints of interface.
Comments
Post a Comment