Game Development Community

Invalid offsetof from non-POD type

by J. Donavan Stanley · in Torque Game Engine · 03/28/2003 (6:02 am) · 3 replies

I get a ton of these warnings under Linux... Any idea how to 1) Fix them or 2) Turn them off?

Searching the web reveals other apps with the same problem but no solutions. Searching the GCC man pages and manual came up empty too.

#1
03/28/2003 (7:47 am)
This warning was introduced with gcc3.

There is no way to turn them off, short of changing the gcc3 source code or using the -w flag to turn of _all_ warnings.

The problem is the way torque sets up bindings with the scripting language. It uses the c offsetof macro on the fields of console objects, to compute a relative offset that i think is later used when the field needs to be read/write by the scripting language.

However, a c++-class is non-POD ("Plain Old Data"), and the c++ standard apparently says that you should not use offsetof on such structures.

Despite the hundreds of lines of warings, the resulting executable still seems to work fine. I think the warning may be overly broad. I emailed the person who added this code to gcc but I received no response.

I don't think changing this in torque will be a simple task. The compiler suggests "use pointer to member instead". To do this we would need to build a table of all console objects and fetch the appropriate one when a field is accessed. The beautity of the current system is that the offsets are computed once in a static method, and can be used for any object.

Soon, I'm going to email the gcc mailing list about it. What I want to find is a case where the warning fires, and the resulting code is invalid. If this isn't happening in torque, then I don't see why we should change the code. Instead, maybe gcc should have a flag to disable the warning.

Edit: just posted to the mailing list about this...we'll see what they say.
#2
04/26/2003 (8:16 pm)
I checked in a workaround for this that squelches the warning. Let me know if it causes problems.
#3
04/26/2003 (8:53 pm)
Wow ! This will be really appreciated ! Thanks much for this John