Closed Bug 243018 Opened 20 years ago Closed 13 years ago

Gcc-3.4.0 compiler warnings

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: tenthumbs, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [build_warning])

I have no idea how important this really is but gcc has these warnings.

jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object  
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:423: warning: ISO C forbids conversion of object pointer to function 
   pointer type
jsinterp.c:4151: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4151: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4264: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4264: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4331: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4331: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4429: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4434: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsobj.c:1429: warning: ISO C forbids conversion of object pointer to function 
  pointer type
jsobj.c:1460: warning: ISO C forbids conversion of object pointer to function 
  pointer type
It's legal to convert a function pointer to a suitably large integral or object
pointer type so long as you convert the pointer back to a function pointer of
the correct type before using it.  I thought there was a check that function
pointers fit but I cannot find it at the moment.
I'm told that while that's true for C++, it's a common extension but not
required to be supported in ISO C.  *sigh*
Yeah, ISO C blew it.  Any C99 hope?

/be
Doesn't look like it.  From the C99 supplementary rationale v5.10 section
6.3.2.3 under "Consequences of the treatment of pointer types":

Even with an explicit cast, it is invalid to convert a function pointer to an
object pointer or a pointer to void, or vice versa.
Brendan: those compiler warnings are technically correct.
(Note that it is legal to cast a pointer to a function
to a pointer to another function type.)

By the way, this is why we added a new NSPR function
PR_FindFunctionSymbol that returns a function pointer
because PR_FindSymbol returns a data pointer (void*).

http://lxr.mozilla.org/nspr/source/nsprpub/pr/include/prlink.h#196
This is some old crack-baby concession to Crays or Cybers, or some other dead
architecture that had goofy 48-bit segmented code pointers but 32-bit data, or
something even weirder.  If it mattered, C++ would match it.  I intend to ignore
it ;-).

/be
Brendan: are you sure C++ allows this?
Wan-Teh: I'm parroting comment #2 on C++ not being as lame as C.  Cc'ing dbaron
in case he knows for sure.

/be
Digging into this further, it appears that standard C++ has gone from allowing
explicit conversions, to allowing explicit and implicit conversions, to
disallowing all conversions.  Which would put the latest version in the same
boat as ISO C.  I do note that it's proposed to further change to allow explicit
conversions with implementation defined behavior.

Through all of this, it appears legal to cast a function pointer to a suitably
large integral type to an object pointer and back again.

I hope dbaron can shed some light on this.

And for wtc, isn't it required that the two function types have the same linkage
type for the cast to be valid?
-> default qa
QA Contact: pschwartau → general
Whiteboard: [build_warning]
Blocks: buildwarning
jsdbgapi.c file might have been renamed to jsdbgapi.cpp which have removed the warnings. There is no warning reported by this bug in windows, linux and osx builds (nightly builds). 
Hence closing the bug.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.