This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On 05/17/2006 11:12, Gabriel Dos Reis wrote:
| They prevent from introducing safe C++ code.

I don't understand that comment.

Look at this: ------------------------ header.h:

extern "C" {
  struct spinlock_t {};
  struct device_t
  {
    struct spinlock_t spinlock;
    char flags;
  };
  void do_something(device_t* device);
} //extern "C"
------------------------
driver.c:

#include <header.h>

void do_something(device_t* device)
{
   if (device->flags) do1();
   else do2();
}
------------------------
user.cpp:

#include <header.h>

void user()
{
device_t device;
device.flags=0x55;
do_something(&device); //run-time crash
}
------------------------
Header.h and driver.c are old GCC code using all possible GCC extensions. User.cpp is an attempt for C++ to co-exist in the Linux kernel. To make driver.c and user.cpp, linked together, to work as they should, one needs to do something with extern "C" struct spinlock_t {};. Currently, there is no compiler help for the user compiling his user.cpp file to know about such misbehavior.


Roman


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]