c - Can we mix __extension__ and -std=c99? -


the standard doesn't allow convert between pointers void * , pointers functions:

6.3.2.3:8 pointer function of 1 type may converted pointer function of type , again; result shall compare equal original pointer. if converted pointer used call function type not compatible pointed-to type, behavior undefined.

there several functions in glib/gtk breaking rule, example g_signal_handlers_block_by_func

a typical example converting uppercase in gtkentry:

void insert_text_handler (gtkeditable *editable,                      const gchar *text,                      gint         length,                      gint        *position,                      gpointer     data) {   gchar *result = g_utf8_strup (text, length);    g_signal_handlers_block_by_func (editable,                                (gpointer) insert_text_handler, data);   gtk_editable_insert_text (editable, result, length, position);   g_signal_handlers_unblock_by_func (editable,                                      (gpointer) insert_text_handler, data);    g_signal_stop_emission_by_name (editable, "insert_text");    g_free (result); } 

gpointer typedef void * , g_signal_handlers_unblock_by_func implemented using gpointer:

guint g_signal_handlers_block_matched(gpointer instance,                            gsignalmatchtype   mask,                            guint          signal_id,                            gquark         detail,                            gclosure      *closure,                            gpointer       func,                            gpointer       data);  #define g_signal_handlers_block_by_func(instance, func, data)                           \     g_signal_handlers_block_matched((instance),                             \                           (gsignalmatchtype) (g_signal_match_func | g_signal_match_data),   \                           0, 0, null, (func), (data)) 

thus, compiling code using -std=c99 gives following warning:

src/client/gui.c: in function ‘insert_text_handler’: src/client/gui.c:474:45: warning: iso c forbids conversion of function pointer object pointer type [-wpedantic]    g_signal_handlers_block_by_func(editable, (gpointer)insert_text_handler, data); 

and way can find silence compiler using __extension__:

__extension__ g_signal_handlers_block_by_func (editable, (gpointer)insert_text_handler, data); 

sorry such long preamble can see glib / gtk using gcc extensions , there no way compile in -pedantic mode (without warnings) gtk program using signal handlers.

my question is:

can use -std=c99 in conjunction __extension__ or forced use -std=gnu99?

in other words, __extension__ implies (forces) compiling extensions or instruction silence compiler , program working under undefined behaviour?

what can if know object pointers , function pointers have same representation on given platform, convert integer type in between.

conversions can done between integers , pointer types - not undefined merely implementation-defined behavior (6.3.2.3, §4 , §5).

example:

typedef void funcptr_t (void); ... funcptr_t* fptr = func; void* vptr = (void*)(uintptr_t)fptr; 

this implementation-defined behavior , should not generate diagnostics.

note that:

  • void* vptr = fptr; invalid conversion/undefined behavior.
  • void* vptr = (uintptr_t)fptr; invalid c syntax - constraint violation of simple assignment.

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -