Possible compile issue in PtexHalf.cpp

22 views
Skip to first unread message

Larry Gritz

unread,
Feb 12, 2015, 12:25:50 AM2/12/15
to pt...@googlegroups.com
Somebody compiling OIIO (which embeds Ptex code) using gcc 5.0 noticed a new warning (and error, if using -Werror) that had not been flagged by earlier versions of gcc or by clang.

PtexHalf.cpp has a declaration:

static bool PtexHalfInitialized = PtexHalfInit();

This bool is never referenced elsewhere in the file, but its point is just to initialize, thus calling PtexHalfInit(), which fills in the f2hTable and h2fTable.

But interestingly, because it's 'static' (local module scope visibility only) and yet never referenced, in gcc 5.0 it pops up as an unused variable warning.

As a quick workaround, removing the 'static' keyword (and thus making it a globally visible symbol) makes the warning go away. I don't know if you like that as a final solution, but thought I'd give you the heads-up that gcc 5.0 will trigger the warning.

Personally, I would tend to consider this a gcc error -- I think a variable should not be flagged as unused if its initialization runs code that might have other side effects, as this one does. But I'm not inclined at the moment to read the C++ spec in such detail as to confidently tell gcc that they are wrong. I'll leave that for somebody else.


--
Larry Gritz
l...@larrygritz.com



Brent Burley

unread,
Feb 12, 2015, 11:12:24 AM2/12/15
to pt...@googlegroups.com
Interesting.  I found a discussion about a similar issue here: http://stackoverflow.com/questions/1229430/how-do-i-prevent-my-unused-global-variables-being-compiled-out
One reply suggests using volatile to tell the compiler that the variable is "special".  I'm curious whether that would work (I don't have ready access to gcc 5) but it seems a bit hacky to me.

I suppose I should just use a static array initializer like OpenExr's half though I don't think I would bother with generating it at compile time.  At one time I also implemented a bit-fiddly version of halfToFloat which seemed like a good idea.  It was slightly slower than the table at the time so I dropped it.  It might actually be faster nowadays on the newest platforms.




--

---
You received this message because you are subscribed to the Google Groups "ptex" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ptex+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brent Burley

unread,
Feb 12, 2015, 11:45:21 AM2/12/15
to pt...@googlegroups.com
I've pushed v2.0.62 which now uses static array initializers for the tables - no more unused variable.
Reply all
Reply to author
Forward
0 new messages