Benjamin Goldberg <[EMAIL PROTECTED]> wrote: > #define PARROT_DECLARE_STATIC_STRING(name, cstring) \
[ big snip ] While Juergen's original or your proposal are fine, they don't work (or not as proposed). First there are compiler issues: $ gcc -Iinclude -Lblib/lib -lparrot -ldl -Wall -g bg.c && ./a.out #v+ bg.c: In function `main': bg.c:35: warning: braces around scalar initializer bg.c:35: warning: (near initialization for `_Parrot_static_mystr_STRING.obj.u.int_val') bg.c:35: warning: initialization makes integer from pointer without a cast bg.c:35: warning: excess elements in scalar initializer bg.c:35: warning: (near initialization for `_Parrot_static_mystr_STRING.obj.u.int_val') #v- The declaration looks ok at first sight, my gcc 2.95.2 might be wrong, but anyway, a bigger problem is here: PIO_printf(interpreter, "%S\n", mystr); Program received signal SIGSEGV, Segmentation fault. 0x400f8725 in make_COW_reference (interpreter=0x8049828, s=0x80486e0) at string.c:95 95 PObj_constant_CLEAR(s); (gdb) bac #0 0x400f8725 in make_COW_reference (interpreter=0x8049828, s=0x80486e0) at string.c:95 #1 0x400f91b6 in string_copy (interpreter=0x8049828, s=0x80486e0) at string.c:497 snippet from objdump: .rodata 00000011 _Parrot_static_mystr_cstring.15 .rodata 00000024 _Parrot_static_mystr_STRING.16 If we get a general compiler independend solution for declaring static STRINGs we still have nothing for static keys. leo #include "parrot/parrot.h" #include "parrot/embed.h" #if ! DISABLE_GC_DEBUG # define GC_DEBUG_VERSION ,0 #else # define GC_DEBUG_VERSION #endif #define PCONCAT(b,c) _Parrot_static_##b##c #define PARROT_DECLARE_STATIC_STRING(name, cstring) \ static const char PCONCAT(name,_cstring) * = cstring; \ static const struct parrot_string_t \ PCONCAT(name,_STRING) = { \ { /* pobj_t */ \ {{ \ (void*)PCONCAT(name,_cstring), \ sizeof(PCONCAT(name,_cstring)) \ }}, \ PObj_constant_FLAG \ GC_DEBUG_VERSION \ }, \ sizeof(PCONCAT(name,_cstring)), \ (void*)PCONCAT(name,_cstring), \ sizeof(PCONCAT(name,_cstring)) - 1, \ NULL, \ NULL, \ 0 \ }, * const name = &PCONCAT(name,_STRING) int main(int argc, char* argv[]) { int dummy_var; struct Parrot_Interp * interpreter; PARROT_DECLARE_STATIC_STRING(mystr, "some string here"); interpreter = Parrot_new(); Parrot_init(interpreter, (void*) &dummy_var); PIO_printf(interpreter, "%S\n", mystr); return 0; }