c++ - What is/are G_STMT_START and G_STMT_END? -


i'm in process of porting code gimp source code base program writing. part of code (/gimp-2.8.10//modules/display-filter-color-blind.c) references macro called gimp_cairo_argb32_set_pixel (gimp-2.8.10//libgimpcolor/gimpcairocolor.h). within macro there called g_stmt_start/g_stmt_end. compiler (mac osx via xcode default compiler) complaining error "use of undeclared identifier 'g_stmt_start'" know not scoping issue put macros (in header file called globals.h include in .h) because compiler not complaining gimp_cairo_argb32_set_pixel define.

does know whats going on here? i've attempted grep through instances of g_stmt_start in gimp source have not found seems define g_stmt_start/g_stmt_end. found sort of an explanation in gimp toolkit documentation, it's far helpful (for me @ least).

this full macro trying use:

/**  * gimp_cairo_argb32_set_pixel:  * @d: pointer destination buffer  * @r: red component, not pre-multiplied  * @g: green component, not pre-multiplied  * @b: blue component, not pre-multiplied  * @a: alpha component  *  * sets single pixel in cairo image surface in %cairo_format_argb32.  *  * since: gimp 2.6  **/ #if g_byte_order == g_little_endian #define gimp_cairo_argb32_set_pixel(d, r, g, b, a) \   g_stmt_start {                                   \     const guint tr = (a) * (r) + 0x80;             \     const guint tg = (a) * (g) + 0x80;             \     const guint tb = (a) * (b) + 0x80;             \     (d)[0] = (((tb) >> 8) + (tb)) >> 8;            \     (d)[1] = (((tg) >> 8) + (tg)) >> 8;            \     (d)[2] = (((tr) >> 8) + (tr)) >> 8;            \     (d)[3] = (a);                                  \   } g_stmt_end #else #define gimp_cairo_argb32_set_pixel(d, r, g, b, a) \   g_stmt_start {                                   \     const guint tr = (a) * (r) + 0x80;             \     const guint tg = (a) * (g) + 0x80;             \     const guint tb = (a) * (b) + 0x80;             \     (d)[0] = (a);                                  \     (d)[1] = (((tr) >> 8) + (tr)) >> 8;            \     (d)[2] = (((tg) >> 8) + (tg)) >> 8;            \     (d)[3] = (((tb) >> 8) + (tb)) >> 8;            \   } g_stmt_end #endif 

thanks this!

i had no idea might either (although know, i'm telling myself have guessed), took find out entering g_stmt_start google , clicking on the first result.

that page, documentation glib manual, reveals macro designed used within multi-statement macros.

g_stmt_start

#define     g_stmt_start 

used within multi-statement macros can used in places 1 statement expected compiler.

g_stmt_end

#define     g_stmt_end 

used within multi-statement macros can used in places 1 statement expected compiler.

later on in search results, you'll 1 or more copies of gmacros.h header file, these macros defined:

/* provide simple macro statement wrappers (adapted perl):  *  g_stmt_start { statements; } g_stmt_end;  *  can used single statement, in  *  if (x) g_stmt_start { ... } g_stmt_end; else ...  *  *  gcc wrap statements within `({' , `})' braces.  *  sunos wrapped within `if (1)' , `else (void) 0',  *  , otherwise within `do' , `while (0)'.  */ #if !(defined (g_stmt_start) && defined (g_stmt_end)) #  if defined (__gnuc__) && !defined (__strict_ansi__) && !defined (__cplusplus) #    define g_stmt_start    (void) __extension__ ( #    define g_stmt_end      ) #  else #    if (defined (sun) || defined (__sun__)) #      define g_stmt_start  if (1) #      define g_stmt_end    else (void)0 #    else #      define g_stmt_start  #      define g_stmt_end    while (0) #    endif #  endif #endif 

from that, becomes pretty clear these macros implementing the standard idiom, except on gcc use extension intended precisely purpose.

i'd figure there other parts of gimp code depend on glib headers, you'll want include them if you're using code. if not, there's enough information here implement relevant portions of code yourself.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -