Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

grrrrr. #define should be typedef

5 views
Skip to first unread message

Nicholas Clark

unread,
Jun 11, 2004, 5:50:43 AM6/11/04
to perl6-i...@perl.org
Any reason *not* to make this change:

Index: include/parrot/string.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/string.h,v
retrieving revision 1.59
diff -d -u -r1.59 string.h
--- include/parrot/string.h 22 Apr 2004 08:55:06 -0000 1.59
+++ include/parrot/string.h 11 Jun 2004 09:46:36 -0000
@@ -54,7 +54,7 @@
#define STRINGINFO_STRLEN 6

/* &end_gen */
-#define STRING struct parrot_string_t
+typedef struct parrot_string_t STRING;

#endif /* PARROT_IN_CORE */
#endif /* PARROT_STRING_H_GUARD */

Witness the pain that using the pre-processor causes:

(gdb) down
#0 0x00034114 in char8_at (offs=12, context=0xb003f850) at src/string.c:2918
2918 return ((char*)((STRING *)context)->strstart)[offs];
(gdb) print (STRING *)context)
No symbol "STRING" in current context.


followed by swearing and cursing and time wasted grepping to find out what
a STRING is.

Is there any reason not to have a coding standard that typedef should be
used whenever possible (and non-uses must have their reason commented?)

Nicholas Clark

Dan Sugalski

unread,
Jun 11, 2004, 8:30:39 AM6/11/04
to Nicholas Clark, perl6-i...@perl.org
At 10:50 AM +0100 6/11/04, Nicholas Clark wrote:
>Is there any reason not to have a coding standard that typedef should be
>used whenever possible (and non-uses must have their reason commented?)

Nope. So mote it be. typedefs for types, #defines for constants and
bizarre (*temporary*!) debugging things.
--
Dan

--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

0 new messages