Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Strange warnings when compiling CVS...

<< < (3/4) > >>

thomas:
I fixed it :lol: :lol: :lol:

Actually it is pretty obvious what you have to do, read the error message :)


--- Code: ---#undef offsetof
#define offsetof(T, M) ( reinterpret_cast <size_t> ( & reinterpret_cast <const volatile char &>(reinterpret_cast<T *> (1000)->M) ) - 1000u)

--- End code ---

Now say again that macros are not evil  8)

thomas:
Seriously now... I know it is a hack and a macro on top.

But offsetof is a hack anyway (and a macro too).

With the casts added to wxScintilla (r1512), I can compile Code::Blocks with zero warnings when putting this offsetof replacement into scriptbindings.cpp (I hope it is really a 100% valid replacement, but I think so... at least it does not crash me). Yes, zero warnings. Repeat that.
This means that any real warnings are now a lot easier to spot.

Shouldn't we go for that workaround then? We know these warnings are not related to a bug, so they are utterly useless. And the macro won't affect any other files if it is located in the cpp file.

After all, why do we compile with -Wall if we get so many useless warnings that we don't see the real ones anyway ;)

Michael:

--- Quote from: thomas on December 15, 2005, 11:49:44 am ---I fixed it :lol: :lol: :lol:

Actually it is pretty obvious what you have to do, read the error message :)


--- Code: ---#undef offsetof
#define offsetof(T, M) ( reinterpret_cast <size_t> ( & reinterpret_cast <const volatile char &>(reinterpret_cast<T *> (1000)->M) ) - 1000u)

--- End code ---

Now say again that macros are not evilĀ  8)

--- End quote ---

Could not be used instead of a macro an inline function?

Michael

thomas:
No.

EDIT:

Slightly longer answer:
Technically, yes, but
- it is a lot more complicated
- you may have to create a temporary object (I am not sure if you can trick the compiler to do it on a pointer)
- you still must #undef offsetof, so you use preprocessor commands either way
- you need a different calling convention, meaning you have to rewrite the existing code
- you have additional constraints that offsetof has not (so it may not always work)
- it is still a hack

tiwag:
@thomas
now i get the 20 warnings from offsetof in scriptbindings.cpp again,
but i think i'm not dreaming that your changed offsetof macro definition was already in SVN ? right?

now it isn't anymore in SVN ? why ?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version