gcc v5+ generates code that cause segment faults

Michael J. Fuhrman mfuhrman@enetarch.net
Thu Oct 6 23:50:00 GMT 2016


Per Anonymous's lead ...

I researched gcc Embedded Functions:
https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

Apparently, his description of how the functions work, AKA they can only 
be used when the external parent function is executing, is correct. 
Sad, really. As all the other compilers don't treat embedded functions 
this way.

To test this theory, I moved the parent function .. JSON .. so that it 
just enclosed the malloc expressions.  The code compiled correctly, and 
executed correctly.

/me sighs.

Here is a discussion on the merits of Internal vs External encapsulation.

http://stackoverflow.com/questions/2929281/are-nested-functions-a-bad-thing-in-gcc

As for me, I was using it for scope resolution.  Helping to make the 
code more OO, as well as help avoid naming conflicts between various C 
modules.

It should not matter if the functions are internal or external, though, 
internal functions should not have an expectation to internal variables, 
as they do in an OO environment.  And, I think the use of labels to 
create the OO effect in C is a waste typing.  Plus it breaks with C's 
conventions of no GOTO statements.

The source was updated on GitHub
http://www.github.com/enetarch/cjson

Mike




More information about the Gcc-help mailing list