This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

__VA_ARGS__ patch for cccp.c



This small patch enables variable arguments for macros in the same style as         
in my copy of the draft c9x standard.                                     
                
it essentially treats ... as __VA_ARGS__..., as in:
                
#define msg(...) printf (__VA_ARGS__);               
                
so msg(a,b,c) expands to printf(a,b,c); 
                
note also that this is always enabled (it doesn't clash with the older
syntax), as was the arg... syntax (hmm, why is this enabled even with
-pedantic?)

is this the right thing to do? did I read the standard correctly? 
i'll add documentation and do the necessary corrections later next week,
just check it out if you want...

Index: cccp.c
===================================================================
RCS file: /home/cvsroot/egcs/gcc/cccp.c,v
retrieving revision 1.7
diff -u -p -r1.7 cccp.c
--- cccp.c	1998/02/16 06:58:13	1.7
+++ cccp.c	1998/03/08 16:34:51
@@ -5553,22 +5553,39 @@ create_definition (buf, limit, op)
 		 rest_extension);
 
       if (!is_idstart[*bp])
-	pedwarn ("invalid character in macro parameter name");
-      
-      /* Find the end of the arg name.  */
-      while (is_idchar[*bp]) {
-	bp++;
-	/* do we have a "special" rest-args extension here? */
-	if (limit - bp > REST_EXTENSION_LENGTH
-	    && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
-	  rest_args = 1;
-	  temp->rest_args = 1;
-	  break;
+        {
+          /* parse '...' parameter and treat the same as '__VA_ARGS__...'.  */
+	  if (limit - bp > REST_EXTENSION_LENGTH
+	      && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0)
+	    {
+	      rest_args = 1;
+	      temp->name = "__VA_ARGS__";
+	      temp->length = 11;
+	      temp->rest_args = 1;
+	      bp += REST_EXTENSION_LENGTH;
+	    }
+	  else
+	    pedwarn ("invalid character in macro parameter name");
 	}
-      }
-      temp->length = bp - temp->name;
-      if (rest_args == 1)
-	bp += REST_EXTENSION_LENGTH;
+      else
+        {
+          /* Find the end of the arg name.  */
+          while (is_idchar[*bp]) {
+	    bp++;
+	    /* do we have a "special" rest-args extension here? */
+	    if (limit - bp > REST_EXTENSION_LENGTH
+	        && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
+	      rest_args = 1;
+	      temp->rest_args = 1;
+	      break;
+	    }
+          }
+          
+          temp->length = bp - temp->name;
+          if (rest_args == 1)
+            bp += REST_EXTENSION_LENGTH;
+        }
+      
       arglengths += temp->length + 2;
       SKIP_WHITE_SPACE (bp);
       if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
@@ -5578,8 +5595,8 @@ create_definition (buf, limit, op)
       if (*bp == ',') {
 	bp++;
 	SKIP_WHITE_SPACE (bp);
-	/* A comma at this point can only be followed by an identifier.  */
-	if (!is_idstart[*bp]) {
+	/* A comma at this point can only be followed by an identifier or an '...'.  */
+	if (!is_idstart[*bp] && *bp != '.') {
 	  error ("badly punctuated parameter list in `#define'");
 	  goto nope;
 	}

      -----==-                                              |
      ----==-- _                                            |
      ---==---(_)__  __ ____  __       Marc Lehmann       +--
      --==---/ / _ \/ // /\ \/ /       pcg@goof.com       |e|
      -=====/_/_//_/\_,_/ /_/\_\                          --+
    The choice of a GNU generation                        |
                                                          |


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]