Re: Using structs as custom protocol headers

From: Derk Gwen (
Date: 04/02/03

From: Derk Gwen <>
Date: Wed, 02 Apr 2003 03:26:45 -0000

# Ok. He (the lecturer) thinks structs can be used if "youre carefull",
# i'd like to use them but if you and he say it's difficult then I'd
# probably be foolish to try.

If you're using the same compiler on the same hardware with the same options,
that would be being careful. The problem is that a C compiler will layout the
fields in the same order, but is allowed to put invisible padding bytes in the
layout as well. And different compilers, or different versions of the same
compiler can pad a structure in different ways.

# Ive done a bit of reading on endian-ness and know I have to convert
# the IP and port number, but do I have to convert all the data as
# well?

I try do it on all integers I output to a file or socket. That way I know I
can read in on any other machine.

Derk Gwen
I have no respect for people with no shopping agenda.

Relevant Pages

  • Re: struct layout
    ... I have a doubt regarding the layout of structs in C. ... You can use preprocessor macros for this, or you could use an enum. ... Preprocessor constants are not available to the compiler and also no to ...
  • Re: how is a struct represented internally.
    ... if the compiler decided to optimize the structures ... structs with identical initial layout, wich would break under a compiler ... that wouldn't lay out those structs the same way. ... there that simply assumes that there is such a guarantee. ...
  • Re: Types in C
    ... Structs and unions are user-defined. ... definitions without direct compiler support. ... be portable to compilers that don't have inline functions". ...
  • Re: Dynamically load a dll and us it (in a rexx dll)
    ... The available API functions are dependent on the ODBC version ... The default is usually compiler dependent. ... Depending on the data types used in the structs you ... leave .dll out, it just mentioned path. ...
  • Re: C needs to grow up a little, move with the times, expand its horizons
    ... Interface is special structure ... that is separated from structs and there are no vtable pointers ... Two new languages go with this scheme: ... The compiler would look for the "myFunction" by name, ...