[C++ PATCH] warning about empty extern "C" structures

Roman Kononov kononov195-far@yahoo.com
Tue Jun 20 14:10:00 GMT 2006


On 06/20/2006 09:52, Gabriel Dos Reis wrote:
> Roman Kononov <kononov195-far@yahoo.com> writes:
> 
> | On 05/17/2006 22:08, Andrew Pinski wrote:
> | > On May 17, 2006, at 8:03 PM, Roman Kononov wrote:
> | >
> | >>
> | >> extern "C" {
> | >>   static inline int foo(int socket) {
> | >>      struct empty_t {};
> | >>      struct network_message_t {
> | >>         empty_t foo;
> | >>         int stuff;
> | >>      } msg;
> | >>      msg.stuff=0;
> | >>      return send(socket,&msg,sizeof(msg));
> | >>   }
> | >> }
> | >>
> | >> We would like foo() to send same message from C++ and C code.
> | > That is just bogus.  Why have an empty struct in there in the first
> | > place.
> | > The only place empty structs come handy is where they don't store data
> | > and are needed to pass around as pointers like a lock (though I don't
> | > think that is a good use anyways).
> | 
> | It is not bogus. Instead of just
> | 
> |    struct empty_t {};
> | 
> | think about this:
> | 
> |    struct empty_t {
> |        #ifdef MSG_DEBUG
> |           int debug;
> |        #endif
> |        #ifdef MAGIC
> |           long magic;
> |        #endif
> |        /*and so on for few pages*/
> |    };
> 
> the point is?

The point was that empty structs may come handy for a different reason, 
which make the above code real.

Roman



More information about the Gcc-patches mailing list