Re: strange problem with send() and recv()



Dave Thompson <david.thompson1@xxxxxxxxxxxxxxxx> writes:
[...]
> As others have noted the STL part is C++ and offtopic in c.l.C, but
> this is relatively small and easily ignorable. "Mixed" declarations
> (that is, not solely at the beginning of a block) and double-slash
> comments which were introduced in C++ _are_ standard in C as of C99,
> but not yet universally implemented. And double-slash comments are
> still unwise in news postings, since those may get line breaks (wraps)
> added at various points, and this breaks // comments but does not harm
> /* */ comments. (It also harms long preprocessor #directives, the only
> other place lines are significant.)

Lines are also significant in string literals. E.g., "splitting this
across lines" will cause problems.

[...]

> In general it's a poor idea to send C-language structs over a network;
> compilers on different types of systems can lay them out differently,
> and sometimes also different compilers or the same compiler with
> different options on the same system type. This is why you see proper
> network protocols specified in terms of actual bits (or nowadays
> usually octets) on the wire and not in C or other HLL. But since you
> apparently are using Wintel and probably the same compiler at both
> (all) endpoints, and structs that are _mostly_ chars, leave that also.

It's not uncommon for structs to be laid out in the same way for
different compilers on the same platform, so there's some hope of
combining code compiled with different compilers, but generally it's
not wise to depend on it.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: How to make C look like C++
    ... let me say that the tone of your answers are very arrogant. ... available on all platforms. ... platforms which don't always have C++ compilers might be new OSes or game ... and using structs and defines instead of classes and consts. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Sending pkts on a socket...
    ... figure out why some structs where bigger than they should be somethimes and ... I think I'm getting away from the original question, but do compilers put ...
    (comp.lang.java.programmer)
  • Re: Compiler error for "wrong" sized type
    ... structs. ... Such extensions are inherently non-portable and you should be very wary ... especially embedded systems I think it can be justified. ...
    (comp.lang.c)
  • Re: Packing netgraph structs
    ... > and we pack/unpack various Netgraph related structs just happily. ... > as well as most if not all other user-accessible Netgraph structs. ... compilers can insert padding at the end of structs at will, ... lead to padding between ng_mesg.header.cmdstr and ng_mesg.data. ...
    (freebsd-net)