From: SourceForge.net <no...@so...> - 2006-04-20 09:05:17
|
Bugs item #1082958, was opened at 2004-12-10 15:55 Message generated for change (Comment added) made by papadopo You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1082958&group_id=2435 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: w32api Group: None Status: Open Resolution: None Priority: 5 Submitted By: Martin Pollard (xmp) Assigned to: Nobody/Anonymous (nobody) Summary: gcc 3.4 and FIELD_OFFSET Initial Comment: I have been using some code that makes use of the following define from winnt.h #define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f)) Unfortunately this doesn't seem to be a valid constant expression in the new c++ parser in 3.4? And I get errors when I try and make use of it in case statements. Could we make use of the offsetof macro in stddef.h to fix this? ---------------------------------------------------------------------- >Comment By: Dimitri Papadopoulos (papadopo) Date: 2006-04-20 11:05 Message: Logged In: YES user_id=52414 Which compiler version fails to compile? If the offsetof has indeed been changed between gcc 2.95.*, gcc 3.*, and gcc 4.*, then we would need different versions of FIELD_OFFSET for different GNU compiler versions. Additionally the Watcom compiler is indeed far from being standard-compliant, I suspect it won't like the new FIELD_OFFSET either. So indeed... It looks like a nightmare to maintain a FIELD_OFFSET macro identical to the offsetof macro bundled with the compiler itself. It's probably better to have the dependency on <stddef.h>... Does the Watcom compiler define offsetof in <stddef.h>? Do I add the <stddef.h> trick for the GNU compiler only? In C++ mode only? About CONTAINING_RECORD, I wasn't aware of this macro. Will have to look into this. ---------------------------------------------------------------------- Comment By: Dimitri Papadopoulos (papadopo) Date: 2006-04-20 10:48 Message: Logged In: YES user_id=52414 About this part of the comment: But why should we change the meaning of the w32api define FIELD_OFFSET anyway? If FIELD_OFFSET, as defined by MS, is not a valid constant expression in C++, the user should be told so. It's just that the GNU compiler doesn't like Microsoft's FIELD_OFFSET macro. The Visual C++ compiler does like it. Besides, the Microsoft implementation of FIELD_OFFSET is irrelevant. As far as I can see the macro is not documented in MSDN, at least I can't find anything in the current online version. Unlike Microsoft, we need to provide a FIELD_OFFSET macro that works with compilers other than Visual C++. ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2006-04-20 10:27 Message: Logged In: YES user_id=11494 The fix is broken: Here is a testcase. #include <stddef.h> #define FIELD_OFFSET(t,f) (reinterpret_cast<long> \ (&reinterpret_cast<char&>(static_cast<t*>(0)->f) struct choke_me { int size; char storage[1]; }; struct is_offset_broken { #ifdef USE_STDDEF static const int offset = offsetof (choke_me, storage); #else static const int offset = FIELD_OFFSET (choke_me, storage); #endif }; The safe way to change the meaning of FIELD_OFFSET would be to include stddef.h. Note the gcc internal offsetof API for C++ has changed between gcc-2.95->gcc-3.4.x- >gcc.4.x. Note also that Watcom uses w32api so needs a __GNUC__ guard. Things like CONTAINING_RECORD would also need change for consistency??? But why should we change the meaning of the w32api define FIELD_OFFSET anyway? If FIELD_OFFSET, as defined by MS, is not a valid constant expression in C++, the user should be told so. Danny ---------------------------------------------------------------------- Comment By: Dimitri Papadopoulos (papadopo) Date: 2006-04-19 10:41 Message: Logged In: YES user_id=52414 The problem you report has caused modification in some fashion in the official CVS for the given package. The w32api and mingw-runtime official CVS reside in the winsup CVS directory tree for Cygwin. Those package CVS trees are periodically merged into the MinGW CVS tree. If you still find problems then please open a new report. ---------------------------------------------------------------------- Comment By: Dimitri Papadopoulos (papadopo) Date: 2006-04-14 17:45 Message: Logged In: YES user_id=52414 But shouldn't this be fixed directly in w32api by replacing: #define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f)) by the offsetof macro or better a copy of the offsetof macro to avoid creating a dependency on <stddef.h>: #ifndef __cplusplus #define FIELD_OFFSET(t,f) ((LONG)&(((t*)0)->f)) #else #define FIELD_OFFSET(t,f) (reinterpret_cast<LONG> \ (&reinterpret_cast<char&>(static_cast<t*>(0)->f))) #endif ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-12-10 23:57 Message: Logged In: YES user_id=11494 What stops you from: #ifdef __GNUC__ #include <stddef.h> #undef FIELD_OFFSET #define FIELD_OFFSET(t,f) offsetof(t,f) #endif Danny ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1082958&group_id=2435 |