[PATCH:xscope,04/24] Convert some for loops to use C99-style inline variable declarations

Submitted by Alan Coopersmith on Sept. 1, 2012, 5:17 a.m.

Details

Message ID 1346476686-4273-5-git-send-email-alan.coopersmith@oracle.com
State Deferred
Headers show

Not browsing as part of any series.

Commit Message

Alan Coopersmith Sept. 1, 2012, 5:17 a.m.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
---
 common.c        |    3 +--
 decode11.c      |   14 ++++++--------
 decode_glx.c    |    3 +--
 decode_render.c |    8 +++-----
 fd.c            |    7 ++-----
 print_render.c  |    3 +--
 prtype.c        |   49 ++++++++++++++++---------------------------------
 scope.c         |   15 +++++----------
 table11.c       |    3 +--
 9 files changed, 36 insertions(+), 69 deletions(-)

Patch hide | download patch | download mbox

diff --git a/common.c b/common.c
index c0e9fd6..3c59c0b 100644
--- a/common.c
+++ b/common.c
@@ -196,7 +196,6 @@  SetUpConnectionSocket(int iport, void (*connectionFunc) (int))
 #ifdef USE_XTRANS
     char port[20];
     int partial;
-    int i;
 #else
     FD ConnectionSocket;
     struct sockaddr_in sin;
@@ -230,7 +229,7 @@  SetUpConnectionSocket(int iport, void (*connectionFunc) (int))
         if (ListenTransFds == NULL)
             panic("Can't allocate memory for ListenTransFds");
 
-        for (i = 0; i < ListenTransCount; i++) {
+        for (int i = 0; i < ListenTransCount; i++) {
             int fd = _X11TransGetConnectionNumber(ListenTransConns[i]);
 
             ListenTransFds[i] = fd;
diff --git a/decode11.c b/decode11.c
index 89a4c48..560ca45 100644
--- a/decode11.c
+++ b/decode11.c
@@ -166,14 +166,12 @@  DumpReplyQ(FD fd)
 {
     fprintf(stderr, "ReplyQ[%d] = { Head 0x%lx; Tail 0x%lx }\n", fd,
             (unsigned long) ReplyQ[fd].Head, (unsigned long) ReplyQ[fd].Tail);
-    {
-        struct QueueEntry *p;
-
-        for (p = ReplyQ[fd].Head; p != NULL; p = p->Next)
-            fprintf(stderr,
-                    "0x%lx = { Next 0x%lx; SequenceNumber %ld; Request %d }\n",
-                    (unsigned long) p, (unsigned long) p->Next,
-                    (unsigned long) p->SequenceNumber, p->Request);
+
+    for (struct QueueEntry *p = ReplyQ[fd].Head; p != NULL; p = p->Next) {
+        fprintf(stderr,
+                "0x%lx = { Next 0x%lx; SequenceNumber %ld; Request %d }\n",
+                (unsigned long) p, (unsigned long) p->Next,
+                (unsigned long) p->SequenceNumber, p->Request);
     }
 }
 
diff --git a/decode_glx.c b/decode_glx.c
index b0a732c..fbf749e 100644
--- a/decode_glx.c
+++ b/decode_glx.c
@@ -267,7 +267,6 @@  void
 InitializeGLX(const unsigned char *buf)
 {
     TYPE p;
-    int errcode;
 
     GLXRequest = (unsigned char) (buf[9]);
     GLXEvent = (unsigned char) (buf[10]);
@@ -355,7 +354,7 @@  InitializeGLX(const unsigned char *buf)
 
     InitializeExtensionDecoder(GLXRequest, glx_decode_req, glx_decode_reply);
     InitializeExtensionEventDecoder(GLXEvent, glx_decode_event);
-    for (errcode = GLXError; errcode < (GLXError + GLXNError); errcode++) {
+    for (int errcode = GLXError; errcode < (GLXError + GLXNError); errcode++) {
         InitializeExtensionErrorDecoder(errcode, glx_decode_error);
     }
 }
diff --git a/decode_render.c b/decode_render.c
index 5f62d39..12149e9 100644
--- a/decode_render.c
+++ b/decode_render.c
@@ -355,10 +355,9 @@  static int
 PrintRENDERTRANSFORM(const unsigned char *buf)
 {
     const unsigned char *next = buf;
-    int i, j;
 
-    for (i = 0; i < 3; i++) {
-        for (j = 0; j < 3; j++) {
+    for (int i = 0; i < 3; i++) {
+        for (int j = 0; j < 3; j++) {
             long f = ILong(next);
 
             next += 4;
@@ -378,7 +377,6 @@  void
 InitializeRENDER(const unsigned char *buf)
 {
     TYPE p;
-    int errcode;
 
     RENDERRequest = (unsigned char) (buf[9]);
     RENDERError = (unsigned char) (buf[11]);
@@ -545,7 +543,7 @@  InitializeRENDER(const unsigned char *buf)
 
     InitializeExtensionDecoder(RENDERRequest, render_decode_req,
                                render_decode_reply);
-    for (errcode = RENDERError; errcode < (RENDERError + RENDERNError);
+    for (int errcode = RENDERError; errcode < (RENDERError + RENDERNError);
          errcode++) {
         InitializeExtensionErrorDecoder(errcode, render_decode_error);
     }
diff --git a/fd.c b/fd.c
index c026b0f..00a68a2 100644
--- a/fd.c
+++ b/fd.c
@@ -88,8 +88,6 @@ 
 void
 InitializeFD(void)
 {
-    int i;
-
     enterprocedure("InitializeFD");
     /* get the number of file descriptors the system will let us use */
 #ifdef _SC_OPEN_MAX
@@ -114,7 +112,7 @@  InitializeFD(void)
     }
 
     /* be sure all fd's are closed and marked not busy */
-    for (i = 0; i < MaxFD; i++) {
+    for (int i = 0; i < MaxFD; i++) {
         /* 0, 1, 2 are special (stdin, stdout, stderr) */
         if (i > 2)
             close(i);
@@ -411,7 +409,6 @@  MainLoop(void)
     while (true) {
         fd_set rfds, wfds, xfds;
         short nfds;
-        short fd;
 
         /* wait for something */
 
@@ -472,7 +469,7 @@  MainLoop(void)
         }
 
         /* check each fd to see if it has input */
-        for (fd = 0; fd <= HighestFD; fd++) {
+        for (short fd = 0; fd <= HighestFD; fd++) {
             /*
                check all returned fd's; this prevents
                starvation of later clients by earlier clients
diff --git a/print_render.c b/print_render.c
index f8d14e3..03a3867 100644
--- a/print_render.c
+++ b/print_render.c
@@ -386,12 +386,11 @@  PrintGlyphs(const unsigned char *buf, int n, const char *name)
 {
     const unsigned char *gids;
     const unsigned char *glyphs;
-    int i;
 
     fprintf(stdout, "%s%20s:\n", Leader, name);
     gids = buf;
     glyphs = gids + 4 * n;
-    for (i = 0; i < n; i++) {
+    for (int i = 0; i < n; i++) {
         PrintField(gids, 0, 4, CARD32, "glyphid");
         PrintField(glyphs, 0, 2, CARD16, "width");
         PrintField(glyphs, 2, 2, CARD16, "height");
diff --git a/prtype.c b/prtype.c
index 1fb917d..ef7889a 100644
--- a/prtype.c
+++ b/prtype.c
@@ -126,8 +126,6 @@  static short CurrentLevel = 0;
 void
 SetIndentLevel(short which)
 {
-    short i;
-
     if (which > MaxIndent)
         which = MaxIndent;
     if (which < 0)
@@ -137,7 +135,7 @@  SetIndentLevel(short which)
 
     /* set the indent level to <which> */
     /* -> set the Print Leader to <which> tabs */
-    for (i = 0; i < which; i++)
+    for (short i = 0; i < which; i++)
         Leader[i] = '\t';
     Leader[which] = '\0';
     CurrentLevel = which;
@@ -281,12 +279,9 @@  int
 PrintSTR(const unsigned char *buf)
 {
     /* STR have the length (1 byte) then a string of CHAR8 */
-    short n;
+    short n = IByte(buf++);
 
-    short i;
-
-    n = IByte(buf++);
-    for (i = 0; i < n; i++)
+    for (short i = 0; i < n; i++)
         fprintf(stdout, "%s", printrep(buf[i]));
     return (n + 1);
 }
@@ -761,7 +756,6 @@  PrintList(const unsigned char *buf,
           long number, short ListType, const char *name)
 {
     long n;
-    long i;
     long sum;
 
     if (number == 0)
@@ -773,7 +767,7 @@  PrintList(const unsigned char *buf,
 
     ModifyIndentLevel(1);
     sum = 0;
-    for (i = 0; i < number; i++) {
+    for (long i = 0; i < number; i++) {
         switch (TD[ListType].Type) {
         case BUILTIN:
             n = (*TD[ListType].PrintProc) (buf);
@@ -807,7 +801,6 @@  long
 PrintListSTR(const unsigned char *buf, long number, const char *name)
 {
     long n;
-    long i;
     long sum;
 
     if (number == 0)
@@ -819,7 +812,7 @@  PrintListSTR(const unsigned char *buf, long number, const char *name)
 
     ModifyIndentLevel(1);
     sum = 0;
-    for (i = 0; i < number; i++) {
+    for (long i = 0; i < number; i++) {
         fprintf(stdout, "%s", Leader);
         n = PrintSTR(buf);
         buf = buf + n;
@@ -842,7 +835,6 @@  int
 PrintBytes(const unsigned char *buf, long number, const char *name)
 {
     /* print a list of BYTE -- 8-bit character */
-    long i;
     short column;
 
     if (number == 0)
@@ -850,7 +842,7 @@  PrintBytes(const unsigned char *buf, long number, const char *name)
 
     fprintf(stdout, "%s%20s: ", Leader, name);
     column = SizeofLeader() + 25;
-    for (i = 0; i < number; i++) {
+    for (long i = 0; i < number; i++) {
         if (column > 80) {
             if (Verbose < 2)
                 break;
@@ -877,13 +869,11 @@  PrintBytes(const unsigned char *buf, long number, const char *name)
 int
 PrintString8(const unsigned char *buf, int number, const char *name)
 {
-    short i;
-
     if (number == 0)
         return (0);
 
     fprintf(stdout, "%s%20s: \"", Leader, name);
-    for (i = 0; i < number; i++)
+    for (short i = 0; i < number; i++)
         fprintf(stdout, "%s", printrep(buf[i]));
     fprintf(stdout, "\"\n");
 
@@ -895,15 +885,12 @@  PrintString8(const unsigned char *buf, int number, const char *name)
 int
 PrintString16(const unsigned char *buf, int number, const char *name)
 {
-    long i;
-    unsigned short c;
-
     if (number == 0)
         return (0);
 
     fprintf(stdout, "%s%20s: \"", Leader, name);
-    for (i = 0; i < number * 2; i += 2) {
-        c = IChar2B(&buf[i]);
+    for (long i = 0; i < number * 2; i += 2) {
+        unsigned short  c = IChar2B(&buf[i]);
         fprintf(stdout, "%s", printrep(c));
     }
     fprintf(stdout, "\"\n");
@@ -914,7 +901,6 @@  PrintString16(const unsigned char *buf, int number, const char *name)
 void
 PrintTString8(const unsigned char *buf, long number, const char *name)
 {
-    long i;
     int off;
 
     if (number == 0)
@@ -924,7 +910,7 @@  PrintTString8(const unsigned char *buf, long number, const char *name)
     if (TranslateText)
         off = 0x20;
     fprintf(stdout, "%s%20s: \"", Leader, name);
-    for (i = 0; i < number; i++)
+    for (long i = 0; i < number; i++)
         fprintf(stdout, "%s", printrep(buf[i] + off));
     fprintf(stdout, "\"\n");
 }
@@ -933,8 +919,6 @@  PrintTString8(const unsigned char *buf, long number, const char *name)
 void
 PrintTString16(const unsigned char *buf, long number, const char *name)
 {
-    long i;
-    unsigned short c;
     int off;
 
     if (number == 0)
@@ -944,8 +928,8 @@  PrintTString16(const unsigned char *buf, long number, const char *name)
     if (TranslateText)
         off = 0x20;
     fprintf(stdout, "%s%20s: \"", Leader, name);
-    for (i = 0; i < number * 2; i += 2) {
-        c = IChar2B(&buf[i]);
+    for (long i = 0; i < number * 2; i += 2) {
+        unsigned short c = IChar2B(&buf[i]);
         fprintf(stdout, "%s", printrep(c + off));
     }
     fprintf(stdout, "\"\n");
@@ -1066,12 +1050,11 @@  PrintTextList16(const unsigned char *buf, int length, const char *name)
 void
 DumpHexBuffer(const unsigned char *buf, long n)
 {
-    long i;
-    short column;
-    char h[6]; /* one hex or octal character */
+    short column = 27 + SizeofLeader();
+
+    for (long i = 0; i < n; i++) {
+        char h[6]; /* one hex or octal character */
 
-    column = 27 + SizeofLeader();
-    for (i = 0; i < n; i++) {
         /* get the hex representations */
         sprintf(h, "%02x", (0xff & buf[i]));
 
diff --git a/scope.c b/scope.c
index 2f9befc..ab3b805 100644
--- a/scope.c
+++ b/scope.c
@@ -225,9 +225,7 @@  CMDStringToInt(char *s, int *v)
 static CMDFuncPtr
 CMDStringToFunc(const char *name)
 {
-    int i;
-
-    for (i = 0; i < NumCMDFuncs; i++) {
+    for (int i = 0; i < NumCMDFuncs; i++) {
         if (!strcmp(name, CMDFuncs[i].name) || !strcmp(name, CMDFuncs[i].alias)) {
             return &CMDFuncs[i];
         }
@@ -272,15 +270,14 @@  CMDSplitIntoWords(char *line, char **argv)
 static CMDResult
 CMDHelp(int argc, char **argv)
 {
-    int i;
     CMDFuncPtr func;
 
     if (argc == 1) {
-        for (i = 0; i < NumCMDFuncs; i++)
+        for (int i = 0; i < NumCMDFuncs; i++)
             printf("%-10s%s\n", CMDFuncs[i].name, CMDFuncs[i].usage);
     }
     else {
-        for (i = 1; i < argc; i++) {
+        for (int i = 1; i < argc; i++) {
             func = CMDStringToFunc(argv[i]);
             if (!func) {
                 printf("%-10s unknown command\n", argv[i]);
@@ -389,13 +386,11 @@  static void
 setBreakPoint(void)
 {
     Boolean b = false;
-    BP *bp;
-    FD fd;
 
     if (SingleStep)
         b = true;
     else {
-        for (bp = breakPoints; bp; bp = bp->next) {
+        for (BP *bp = breakPoints; bp; bp = bp->next) {
             if (bp->enabled) {
                 b = true;
                 break;
@@ -404,7 +399,7 @@  setBreakPoint(void)
     }
     if (b != BreakPoint) {
         BreakPoint = b;
-        for (fd = 0; fd < HighestFD; fd++) {
+        for (FD fd = 0; fd < HighestFD; fd++) {
             if (FDD[fd].Busy && FDD[fd].InputHandler == DataFromClient) {
                 if (BreakPoint)
                     SetBufLimit(fd);
diff --git a/table11.c b/table11.c
index 3d9d99c..aaf7a48 100644
--- a/table11.c
+++ b/table11.c
@@ -144,14 +144,13 @@  void
 CreateValueRec(unsigned long key, int size, const unsigned long *def)
 {
     ValuePtr *bucket, value;
-    int i;
 
     bucket = &buckets[HASH(key)];
     value = malloc(sizeof(ValueRec) + (size * sizeof(unsigned long)));
     if (!value)
         return;
     value->values = (unsigned long *) (value + 1);
-    for (i = 0; i < size; i++)
+    for (int i = 0; i < size; i++)
         value->values[i] = ILong((const unsigned char *) (def + i));
     value->size = size;
     value->key = key;

Comments

> From: Alan Coopersmith <alan.coopersmith@oracle.com>
> Date: Fri, 31 Aug 2012 22:17:46 -0700

Please don't do this.  Some OpenBSD platforms are still stuck with GCC
2.95.3.  GCC 2.95.3 is almost a C99 compiler, but doesn't support the
C99 (mis)feature of allowing variable declarations after statements.
That's always been a controversial feature, although using it to
declare loop variables inside a for statement like you're doing here
is fairly widely accepted.

> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
> ---
>  common.c        |    3 +--
>  decode11.c      |   14 ++++++--------
>  decode_glx.c    |    3 +--
>  decode_render.c |    8 +++-----
>  fd.c            |    7 ++-----
>  print_render.c  |    3 +--
>  prtype.c        |   49 ++++++++++++++++---------------------------------
>  scope.c         |   15 +++++----------
>  table11.c       |    3 +--
>  9 files changed, 36 insertions(+), 69 deletions(-)
> 
> diff --git a/common.c b/common.c
> index c0e9fd6..3c59c0b 100644
> --- a/common.c
> +++ b/common.c
> @@ -196,7 +196,6 @@ SetUpConnectionSocket(int iport, void (*connectionFunc) (int))
>  #ifdef USE_XTRANS
>      char port[20];
>      int partial;
> -    int i;
>  #else
>      FD ConnectionSocket;
>      struct sockaddr_in sin;
> @@ -230,7 +229,7 @@ SetUpConnectionSocket(int iport, void (*connectionFunc) (int))
>          if (ListenTransFds == NULL)
>              panic("Can't allocate memory for ListenTransFds");
>  
> -        for (i = 0; i < ListenTransCount; i++) {
> +        for (int i = 0; i < ListenTransCount; i++) {
>              int fd = _X11TransGetConnectionNumber(ListenTransConns[i]);
>  
>              ListenTransFds[i] = fd;
> diff --git a/decode11.c b/decode11.c
> index 89a4c48..560ca45 100644
> --- a/decode11.c
> +++ b/decode11.c
> @@ -166,14 +166,12 @@ DumpReplyQ(FD fd)
>  {
>      fprintf(stderr, "ReplyQ[%d] = { Head 0x%lx; Tail 0x%lx }\n", fd,
>              (unsigned long) ReplyQ[fd].Head, (unsigned long) ReplyQ[fd].Tail);
> -    {
> -        struct QueueEntry *p;
> -
> -        for (p = ReplyQ[fd].Head; p != NULL; p = p->Next)
> -            fprintf(stderr,
> -                    "0x%lx = { Next 0x%lx; SequenceNumber %ld; Request %d }\n",
> -                    (unsigned long) p, (unsigned long) p->Next,
> -                    (unsigned long) p->SequenceNumber, p->Request);
> +
> +    for (struct QueueEntry *p = ReplyQ[fd].Head; p != NULL; p = p->Next) {
> +        fprintf(stderr,
> +                "0x%lx = { Next 0x%lx; SequenceNumber %ld; Request %d }\n",
> +                (unsigned long) p, (unsigned long) p->Next,
> +                (unsigned long) p->SequenceNumber, p->Request);
>      }
>  }
>  
> diff --git a/decode_glx.c b/decode_glx.c
> index b0a732c..fbf749e 100644
> --- a/decode_glx.c
> +++ b/decode_glx.c
> @@ -267,7 +267,6 @@ void
>  InitializeGLX(const unsigned char *buf)
>  {
>      TYPE p;
> -    int errcode;
>  
>      GLXRequest = (unsigned char) (buf[9]);
>      GLXEvent = (unsigned char) (buf[10]);
> @@ -355,7 +354,7 @@ InitializeGLX(const unsigned char *buf)
>  
>      InitializeExtensionDecoder(GLXRequest, glx_decode_req, glx_decode_reply);
>      InitializeExtensionEventDecoder(GLXEvent, glx_decode_event);
> -    for (errcode = GLXError; errcode < (GLXError + GLXNError); errcode++) {
> +    for (int errcode = GLXError; errcode < (GLXError + GLXNError); errcode++) {
>          InitializeExtensionErrorDecoder(errcode, glx_decode_error);
>      }
>  }
> diff --git a/decode_render.c b/decode_render.c
> index 5f62d39..12149e9 100644
> --- a/decode_render.c
> +++ b/decode_render.c
> @@ -355,10 +355,9 @@ static int
>  PrintRENDERTRANSFORM(const unsigned char *buf)
>  {
>      const unsigned char *next = buf;
> -    int i, j;
>  
> -    for (i = 0; i < 3; i++) {
> -        for (j = 0; j < 3; j++) {
> +    for (int i = 0; i < 3; i++) {
> +        for (int j = 0; j < 3; j++) {
>              long f = ILong(next);
>  
>              next += 4;
> @@ -378,7 +377,6 @@ void
>  InitializeRENDER(const unsigned char *buf)
>  {
>      TYPE p;
> -    int errcode;
>  
>      RENDERRequest = (unsigned char) (buf[9]);
>      RENDERError = (unsigned char) (buf[11]);
> @@ -545,7 +543,7 @@ InitializeRENDER(const unsigned char *buf)
>  
>      InitializeExtensionDecoder(RENDERRequest, render_decode_req,
>                                 render_decode_reply);
> -    for (errcode = RENDERError; errcode < (RENDERError + RENDERNError);
> +    for (int errcode = RENDERError; errcode < (RENDERError + RENDERNError);
>           errcode++) {
>          InitializeExtensionErrorDecoder(errcode, render_decode_error);
>      }
> diff --git a/fd.c b/fd.c
> index c026b0f..00a68a2 100644
> --- a/fd.c
> +++ b/fd.c
> @@ -88,8 +88,6 @@
>  void
>  InitializeFD(void)
>  {
> -    int i;
> -
>      enterprocedure("InitializeFD");
>      /* get the number of file descriptors the system will let us use */
>  #ifdef _SC_OPEN_MAX
> @@ -114,7 +112,7 @@ InitializeFD(void)
>      }
>  
>      /* be sure all fd's are closed and marked not busy */
> -    for (i = 0; i < MaxFD; i++) {
> +    for (int i = 0; i < MaxFD; i++) {
>          /* 0, 1, 2 are special (stdin, stdout, stderr) */
>          if (i > 2)
>              close(i);
> @@ -411,7 +409,6 @@ MainLoop(void)
>      while (true) {
>          fd_set rfds, wfds, xfds;
>          short nfds;
> -        short fd;
>  
>          /* wait for something */
>  
> @@ -472,7 +469,7 @@ MainLoop(void)
>          }
>  
>          /* check each fd to see if it has input */
> -        for (fd = 0; fd <= HighestFD; fd++) {
> +        for (short fd = 0; fd <= HighestFD; fd++) {
>              /*
>                 check all returned fd's; this prevents
>                 starvation of later clients by earlier clients
> diff --git a/print_render.c b/print_render.c
> index f8d14e3..03a3867 100644
> --- a/print_render.c
> +++ b/print_render.c
> @@ -386,12 +386,11 @@ PrintGlyphs(const unsigned char *buf, int n, const char *name)
>  {
>      const unsigned char *gids;
>      const unsigned char *glyphs;
> -    int i;
>  
>      fprintf(stdout, "%s%20s:\n", Leader, name);
>      gids = buf;
>      glyphs = gids + 4 * n;
> -    for (i = 0; i < n; i++) {
> +    for (int i = 0; i < n; i++) {
>          PrintField(gids, 0, 4, CARD32, "glyphid");
>          PrintField(glyphs, 0, 2, CARD16, "width");
>          PrintField(glyphs, 2, 2, CARD16, "height");
> diff --git a/prtype.c b/prtype.c
> index 1fb917d..ef7889a 100644
> --- a/prtype.c
> +++ b/prtype.c
> @@ -126,8 +126,6 @@ static short CurrentLevel = 0;
>  void
>  SetIndentLevel(short which)
>  {
> -    short i;
> -
>      if (which > MaxIndent)
>          which = MaxIndent;
>      if (which < 0)
> @@ -137,7 +135,7 @@ SetIndentLevel(short which)
>  
>      /* set the indent level to <which> */
>      /* -> set the Print Leader to <which> tabs */
> -    for (i = 0; i < which; i++)
> +    for (short i = 0; i < which; i++)
>          Leader[i] = '\t';
>      Leader[which] = '\0';
>      CurrentLevel = which;
> @@ -281,12 +279,9 @@ int
>  PrintSTR(const unsigned char *buf)
>  {
>      /* STR have the length (1 byte) then a string of CHAR8 */
> -    short n;
> +    short n = IByte(buf++);
>  
> -    short i;
> -
> -    n = IByte(buf++);
> -    for (i = 0; i < n; i++)
> +    for (short i = 0; i < n; i++)
>          fprintf(stdout, "%s", printrep(buf[i]));
>      return (n + 1);
>  }
> @@ -761,7 +756,6 @@ PrintList(const unsigned char *buf,
>            long number, short ListType, const char *name)
>  {
>      long n;
> -    long i;
>      long sum;
>  
>      if (number == 0)
> @@ -773,7 +767,7 @@ PrintList(const unsigned char *buf,
>  
>      ModifyIndentLevel(1);
>      sum = 0;
> -    for (i = 0; i < number; i++) {
> +    for (long i = 0; i < number; i++) {
>          switch (TD[ListType].Type) {
>          case BUILTIN:
>              n = (*TD[ListType].PrintProc) (buf);
> @@ -807,7 +801,6 @@ long
>  PrintListSTR(const unsigned char *buf, long number, const char *name)
>  {
>      long n;
> -    long i;
>      long sum;
>  
>      if (number == 0)
> @@ -819,7 +812,7 @@ PrintListSTR(const unsigned char *buf, long number, const char *name)
>  
>      ModifyIndentLevel(1);
>      sum = 0;
> -    for (i = 0; i < number; i++) {
> +    for (long i = 0; i < number; i++) {
>          fprintf(stdout, "%s", Leader);
>          n = PrintSTR(buf);
>          buf = buf + n;
> @@ -842,7 +835,6 @@ int
>  PrintBytes(const unsigned char *buf, long number, const char *name)
>  {
>      /* print a list of BYTE -- 8-bit character */
> -    long i;
>      short column;
>  
>      if (number == 0)
> @@ -850,7 +842,7 @@ PrintBytes(const unsigned char *buf, long number, const char *name)
>  
>      fprintf(stdout, "%s%20s: ", Leader, name);
>      column = SizeofLeader() + 25;
> -    for (i = 0; i < number; i++) {
> +    for (long i = 0; i < number; i++) {
>          if (column > 80) {
>              if (Verbose < 2)
>                  break;
> @@ -877,13 +869,11 @@ PrintBytes(const unsigned char *buf, long number, const char *name)
>  int
>  PrintString8(const unsigned char *buf, int number, const char *name)
>  {
> -    short i;
> -
>      if (number == 0)
>          return (0);
>  
>      fprintf(stdout, "%s%20s: \"", Leader, name);
> -    for (i = 0; i < number; i++)
> +    for (short i = 0; i < number; i++)
>          fprintf(stdout, "%s", printrep(buf[i]));
>      fprintf(stdout, "\"\n");
>  
> @@ -895,15 +885,12 @@ PrintString8(const unsigned char *buf, int number, const char *name)
>  int
>  PrintString16(const unsigned char *buf, int number, const char *name)
>  {
> -    long i;
> -    unsigned short c;
> -
>      if (number == 0)
>          return (0);
>  
>      fprintf(stdout, "%s%20s: \"", Leader, name);
> -    for (i = 0; i < number * 2; i += 2) {
> -        c = IChar2B(&buf[i]);
> +    for (long i = 0; i < number * 2; i += 2) {
> +        unsigned short  c = IChar2B(&buf[i]);
>          fprintf(stdout, "%s", printrep(c));
>      }
>      fprintf(stdout, "\"\n");
> @@ -914,7 +901,6 @@ PrintString16(const unsigned char *buf, int number, const char *name)
>  void
>  PrintTString8(const unsigned char *buf, long number, const char *name)
>  {
> -    long i;
>      int off;
>  
>      if (number == 0)
> @@ -924,7 +910,7 @@ PrintTString8(const unsigned char *buf, long number, const char *name)
>      if (TranslateText)
>          off = 0x20;
>      fprintf(stdout, "%s%20s: \"", Leader, name);
> -    for (i = 0; i < number; i++)
> +    for (long i = 0; i < number; i++)
>          fprintf(stdout, "%s", printrep(buf[i] + off));
>      fprintf(stdout, "\"\n");
>  }
> @@ -933,8 +919,6 @@ PrintTString8(const unsigned char *buf, long number, const char *name)
>  void
>  PrintTString16(const unsigned char *buf, long number, const char *name)
>  {
> -    long i;
> -    unsigned short c;
>      int off;
>  
>      if (number == 0)
> @@ -944,8 +928,8 @@ PrintTString16(const unsigned char *buf, long number, const char *name)
>      if (TranslateText)
>          off = 0x20;
>      fprintf(stdout, "%s%20s: \"", Leader, name);
> -    for (i = 0; i < number * 2; i += 2) {
> -        c = IChar2B(&buf[i]);
> +    for (long i = 0; i < number * 2; i += 2) {
> +        unsigned short c = IChar2B(&buf[i]);
>          fprintf(stdout, "%s", printrep(c + off));
>      }
>      fprintf(stdout, "\"\n");
> @@ -1066,12 +1050,11 @@ PrintTextList16(const unsigned char *buf, int length, const char *name)
>  void
>  DumpHexBuffer(const unsigned char *buf, long n)
>  {
> -    long i;
> -    short column;
> -    char h[6]; /* one hex or octal character */
> +    short column = 27 + SizeofLeader();
> +
> +    for (long i = 0; i < n; i++) {
> +        char h[6]; /* one hex or octal character */
>  
> -    column = 27 + SizeofLeader();
> -    for (i = 0; i < n; i++) {
>          /* get the hex representations */
>          sprintf(h, "%02x", (0xff & buf[i]));
>  
> diff --git a/scope.c b/scope.c
> index 2f9befc..ab3b805 100644
> --- a/scope.c
> +++ b/scope.c
> @@ -225,9 +225,7 @@ CMDStringToInt(char *s, int *v)
>  static CMDFuncPtr
>  CMDStringToFunc(const char *name)
>  {
> -    int i;
> -
> -    for (i = 0; i < NumCMDFuncs; i++) {
> +    for (int i = 0; i < NumCMDFuncs; i++) {
>          if (!strcmp(name, CMDFuncs[i].name) || !strcmp(name, CMDFuncs[i].alias)) {
>              return &CMDFuncs[i];
>          }
> @@ -272,15 +270,14 @@ CMDSplitIntoWords(char *line, char **argv)
>  static CMDResult
>  CMDHelp(int argc, char **argv)
>  {
> -    int i;
>      CMDFuncPtr func;
>  
>      if (argc == 1) {
> -        for (i = 0; i < NumCMDFuncs; i++)
> +        for (int i = 0; i < NumCMDFuncs; i++)
>              printf("%-10s%s\n", CMDFuncs[i].name, CMDFuncs[i].usage);
>      }
>      else {
> -        for (i = 1; i < argc; i++) {
> +        for (int i = 1; i < argc; i++) {
>              func = CMDStringToFunc(argv[i]);
>              if (!func) {
>                  printf("%-10s unknown command\n", argv[i]);
> @@ -389,13 +386,11 @@ static void
>  setBreakPoint(void)
>  {
>      Boolean b = false;
> -    BP *bp;
> -    FD fd;
>  
>      if (SingleStep)
>          b = true;
>      else {
> -        for (bp = breakPoints; bp; bp = bp->next) {
> +        for (BP *bp = breakPoints; bp; bp = bp->next) {
>              if (bp->enabled) {
>                  b = true;
>                  break;
> @@ -404,7 +399,7 @@ setBreakPoint(void)
>      }
>      if (b != BreakPoint) {
>          BreakPoint = b;
> -        for (fd = 0; fd < HighestFD; fd++) {
> +        for (FD fd = 0; fd < HighestFD; fd++) {
>              if (FDD[fd].Busy && FDD[fd].InputHandler == DataFromClient) {
>                  if (BreakPoint)
>                      SetBufLimit(fd);
> diff --git a/table11.c b/table11.c
> index 3d9d99c..aaf7a48 100644
> --- a/table11.c
> +++ b/table11.c
> @@ -144,14 +144,13 @@ void
>  CreateValueRec(unsigned long key, int size, const unsigned long *def)
>  {
>      ValuePtr *bucket, value;
> -    int i;
>  
>      bucket = &buckets[HASH(key)];
>      value = malloc(sizeof(ValueRec) + (size * sizeof(unsigned long)));
>      if (!value)
>          return;
>      value->values = (unsigned long *) (value + 1);
> -    for (i = 0; i < size; i++)
> +    for (int i = 0; i < size; i++)
>          value->values[i] = ILong((const unsigned char *) (def + i));
>      value->size = size;
>      value->key = key;
> -- 
> 1.7.9.2
> 
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
Hi,

On 1 September 2012 03:33, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> From: Alan Coopersmith <alan.coopersmith@oracle.com>
>> Date: Fri, 31 Aug 2012 22:17:46 -0700
>
> Please don't do this.  Some OpenBSD platforms are still stuck with GCC
> 2.95.3.  GCC 2.95.3 is almost a C99 compiler, but doesn't support the
> C99 (mis)feature of allowing variable declarations after statements.
> That's always been a controversial feature, although using it to
> declare loop variables inside a for statement like you're doing here
> is fairly widely accepted.

Yes, and 2.95 is thirteen years old.  A teenager which is eyeing off
your car keys.

If a platform still hasn't been updated to a new compiler in that
timeframe, I don't think it's something we should particularly worry
about.

Cheers,
Daniel
On 09/ 1/12 03:33 AM, Mark Kettenis wrote:
>> From: Alan Coopersmith <alan.coopersmith@oracle.com>
>> Date: Fri, 31 Aug 2012 22:17:46 -0700
> 
> Please don't do this.  Some OpenBSD platforms are still stuck with GCC
> 2.95.3.  GCC 2.95.3 is almost a C99 compiler, but doesn't support the
> C99 (mis)feature of allowing variable declarations after statements.
> That's always been a controversial feature, although using it to
> declare loop variables inside a for statement like you're doing here
> is fairly widely accepted.

I admit part of my intent with this patch was finding out if it would cause
problems in X.Org code, in a much less critical area than the core X server.

I do wonder though about the viability of updating some parts of your system
to 2012 releases while keeping others stuck at a 2001 release.   I certainly
don't try to build current X.Org releases on Solaris 8 with our Studio 8
compilers and wouldn't expect anyone else to put in effort to do so.

We're not going to stay gcc 2.95 compatible forever, especially since few of
the rest of us have copies handy to check which subsets it was compatible with
 - it's just a question of how long.   Is work happening on moving to another
compiler such as clang?   Is every software package in the open source universe
holding back for these platforms?   Or are they just being increasingly deprecated?
Hi,

On 1 September 2012 10:21, Alan Coopersmith <alan.coopersmith@oracle.com> wrote:
> I do wonder though about the viability of updating some parts of your system
> to 2012 releases while keeping others stuck at a 2001 release.   I certainly
> don't try to build current X.Org releases on Solaris 8 with our Studio 8
> compilers and wouldn't expect anyone else to put in effort to do so.
>
> We're not going to stay gcc 2.95 compatible forever, especially since few of
> the rest of us have copies handy to check which subsets it was compatible with
>  - it's just a question of how long.   Is work happening on moving to another
> compiler such as clang?   Is every software package in the open source universe
> holding back for these platforms?   Or are they just being increasingly deprecated?

My understanding is that these platforms are m68k (though perhaps not
any longer, as at least Debian has been tracking gcc releases for
quite a long time, including 4.4 now being the default), VAX, and some
even more obscure/esoteric platforms.  Given that I'm pretty sure we
have absolutely no hardware support for them in the server anymore, I
don't think it's worth us putting in any real effort towards it if
no-one has bothered updating the compiler in thirteen years.

My (much) younger sister was born the same year as GCC 2.95.  A couple
of weeks ago, I found out through Facebook that she now has a
boyfriend.  If your compiler is this old, your platform is dead.

In 1999, the world was listening to Britney Spears, the Backstreet
Boys, Mambo No. 5, and TLC's 'No Scrubs'.  Some people even used
Napster 1.0 to download them.  We freaked out about Y2K whilst fending
off Melissa.  People were talking about NATO maybe intervening in
Kosovo, including Russian President Boris Yeltsin, and US President
Bill Clinton (when Ken Starr wasn't trying to impeach him); the EU
were involved too, but were also busy introducing the euro.  We loved
The Matrix, were keenly awaiting Star Wars Episode 1, and hadn't seen
the Blair Witch Project but heard it was a bit shit.  GeoCities was
bought for $3.5 billion, news you might've received via Netscape
Communicator 4.61 or the very first version of MSN Messenger.

East Timor, Interlaken and Columbine.  JFK Jr.  Nelson Mandela.
Seattle WTO.  Dreamcast.  Who Wants to Be a Millionaire - the
premiere.  George Clooney on ER, The Nanny, Melrose Place, and Home
Improvement.

If your compiler lived through all these things, then I'm not bending
over backwards for it.

Cheers,
Daniel
On Sat, Sep 01, 2012 at 10:21:14AM -0700, Alan Coopersmith wrote:
> On 09/ 1/12 03:33 AM, Mark Kettenis wrote:
> >> From: Alan Coopersmith <alan.coopersmith@oracle.com>
> >> Date: Fri, 31 Aug 2012 22:17:46 -0700
> > 
> > Please don't do this.  Some OpenBSD platforms are still stuck with GCC
> > 2.95.3.  GCC 2.95.3 is almost a C99 compiler, but doesn't support the
> > C99 (mis)feature of allowing variable declarations after statements.
> > That's always been a controversial feature, although using it to
> > declare loop variables inside a for statement like you're doing here
> > is fairly widely accepted.
> 
> I admit part of my intent with this patch was finding out if it would cause
> problems in X.Org code, in a much less critical area than the core X server.
> 
> I do wonder though about the viability of updating some parts of your system
> to 2012 releases while keeping others stuck at a 2001 release.   I certainly
> don't try to build current X.Org releases on Solaris 8 with our Studio 8
> compilers and wouldn't expect anyone else to put in effort to do so.
> 
> We're not going to stay gcc 2.95 compatible forever, especially since few of
> the rest of us have copies handy to check which subsets it was compatible with
>  - it's just a question of how long.   Is work happening on moving to another
> compiler such as clang?   Is every software package in the open source universe
> holding back for these platforms?   Or are they just being increasingly deprecated?
> 

Honestly, Mark, I don't agree with you on this, especially for xscope,
which is not even packaged in OpenBSD.

Currently the base X libs still build fine on gcc 2.95 (we
have a few local patches for that, but they are small and easy to
maintain) and so it's not too much burden to continue supporting X on
those architectures.

But I consider that as a potential loss of time, and I'm ready to drop
X support for OpenBSD on those as soon as it become too much work
compared to the possible benefits (ie if someone decides to rewrite
large parts of libs required to build xterm with gcc 2.95.

There is no pratical use of X applications on those platforms, except
the checking that the code is really portable. But I don't think that
vax, m68k and m88k (the 3 concerned architectures) bring in much
additional testing, compared to the other atchitectures supported by
OpenBSD. (sparc64 and macppc are the ones that bring the most
diversity nowadays). Vax's non IEEE FP may be interesting, but... it's
vax only.
> Date: Sat, 01 Sep 2012 10:21:14 -0700
> From: Alan Coopersmith <alan.coopersmith@oracle.com>
> 
> On 09/ 1/12 03:33 AM, Mark Kettenis wrote:
> >> From: Alan Coopersmith <alan.coopersmith@oracle.com>
> >> Date: Fri, 31 Aug 2012 22:17:46 -0700
> > 
> > Please don't do this.  Some OpenBSD platforms are still stuck with GCC
> > 2.95.3.  GCC 2.95.3 is almost a C99 compiler, but doesn't support the
> > C99 (mis)feature of allowing variable declarations after statements.
> > That's always been a controversial feature, although using it to
> > declare loop variables inside a for statement like you're doing here
> > is fairly widely accepted.
> 
> I admit part of my intent with this patch was finding out if it would cause
> problems in X.Org code, in a much less critical area than the core X server.

I guessed as much.  Which is why I actually responded to this be, even
though we don't currently ship xscope on OpenBSD as Matthieu pointed
out.

> We're not going to stay gcc 2.95 compatible forever, especially
> since few of the rest of us have copies handy to check which subsets
> it was compatible with - it's just a question of how long.

I'm certainly not expecting other folks to test compatibility with gcc
2.95.  That burden should lie firmly on the people who care about it.
All I'm asking is that people don't try to actively break things for
us and that patches to fix any problems would still be accepted.

> Is work happening on moving to another compiler such as clang? 

No.  The most important reason to stick with gcc 2.95 is that it is
fast and doesn't need a lot of memory.

> Is every software package in the open source universe holding back for
> these platforms?

No.  But we consider X to be an essential part of the system.

I hope you don't mind that I won't repond to Daniel's somewhat
childish remarks.

Cheers,

Mark
Hi,

On 3 September 2012 21:39, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
> I hope you don't mind that I won't repond to Daniel's somewhat
> childish remarks.

While there may have been a little more levity than needed, there was
a serious point.  The last time your compiler was updated, Boris
Yeltsin was the Russian President.  I don't think it's reasonable to
bother supporting such a platform.

Even if you are committed to supporting bleeding-edge X.Org on m68k,
then Debian has been using gcc 3.x and 4.x for quite some time
(currently 4.4), so have you considered perhaps updating? That would
just leave VAX, and you'll forgive me for being blunt when I say that
I genuinely do not care about X apps on VAX in 2012.

Cheers,
Daniel