# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #15676]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=15676 >


On Sat, Jul 13, 2002 at 10:54:22PM +0100, Nicholas Clark wrote:
> On gcc we turn on -Wpadded
> 
> In file included from include/parrot/interpreter.h:46,
>                  from include/parrot/parrot.h:114,
>                  from register.c:13:
> include/parrot/op.h:80: warning: padding struct to align `arg_count'
> 
> which is this:
> 
> typedef struct {
>     op_type_t type;
>     const char *name;
>     const char *full_name;
>     const char *func_name;
>     const char *body;
>     const char jump;
>     INTVAL arg_count;           /* Includes opcode as one arg */
>     arg_type_t types[PARROT_MAX_ARGS];
>     arg_dir_t dirs[PARROT_MAX_ARGS];
> } op_info_t;
> 
> do we want to leave the warning turned on and have noise, re-order the struct
> to avoid the warning, turn the warning off, or "cheat" in some way by changing
> what jump is (int, same but 3 more chars after it, anonymous union, bitfield
> being 4 ways I can think of that ought to work) ?

The options I considered were

0: Make the char jump field an int. This would increase the size of the struct
   on some platforms, and hence represents wastage.
1: Re-order the struct with the char at the end. This isn't clean:

In file included from include/parrot/interpreter.h:46,
                 from include/parrot/parrot.h:114,
                 from global_setup.c:15:
include/parrot/op.h:83: warning: padding struct size to alignment boundary

2: Replace const char with a bitfield size 8. This isn't clean:

In file included from include/parrot/interpreter.h:46,
                 from include/parrot/parrot.h:114,
                 from global_setup.c:15:
include/parrot/op.h:80: warning: padding struct to align `arg_count'

[grrr. I'd assume that it would silently get rounded up to 32 bits on platforms
where 4 byte alignment was needed, and stay as 1 byte elsewhere. Seems not]

so

3: Change arg_count to a short (does anything really need > 65535 args),
   and make jump an unsigned short. This silences all warnings on arm and x86,
   and should work cleanly on all architectures. (It will generate warnings on
   any platform where sizeof(short)==2, sizeof(int)==8 and ints must be
   aligned, but the only thing close that I know of is a Cray, and there shorts
   are 64 bits)

Nicholas Clark
-- 
Even better than the real thing:        http://nms-cgi.sourceforge.net/

--- include/parrot/op.h.orig    Sat Jul 13 22:39:49 2002
+++ include/parrot/op.h Sat Jul 27 14:22:11 2002
@@ -76,8 +76,8 @@ typedef struct {
     const char *full_name;
     const char *func_name;
     const char *body;
-    const char jump;
-    INTVAL arg_count;           /* Includes opcode as one arg */
+    unsigned short jump;
+    short arg_count;           /* Includes opcode as one arg */
     arg_type_t types[PARROT_MAX_ARGS];
     arg_dir_t dirs[PARROT_MAX_ARGS];
 } op_info_t;


Reply via email to