Jason Moxham on Sat, 27 Jun 2009 02:24:29 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Pari svn on MSVC


From msdn website I got this

c++ would be OK , but for C

// C2057b.c
#define ArraySize1 10
int main() {
  const int ArraySize2 = 10;
  int h[ArraySize2];   // C2057
  int h[ArraySize1];   // OK
}

Jason

----- Original Message ----- From: "Jason Moxham" <jason@njkfrudils.plus.com>
To: <pari-dev@list.cr.yp.to>
Sent: Saturday, June 27, 2009 1:07 AM
Subject: Re: Pari svn on MSVC



----- Original Message ----- From: "Bill Allombert" <Bill.Allombert@math.u-bordeaux1.fr>
To: <pari-dev@list.cr.yp.to>
Sent: Saturday, June 27, 2009 12:49 AM
Subject: Re: Pari svn on MSVC


On Fri, Jun 26, 2009 at 10:59:28PM +0100, Jason Moxham wrote:
in the file
src/language/es.c

in the function

/* print e to S (more efficient than sprintf) */
static void
str_ulong(outString *S, ulong e)
{
 if (e == 0) str_putc(S, '0');
 else
 {
   const int MAX = 21;
   char buf[MAX], *p = buf + MAX;
   *--p = 0;
   if (e > 9) {
     do
       *--p = "0123456789"[e % 10];
     while ((e /= 10) > 9);
   }
   *--p = "0123456789"[e];
   str_puts(S, p);
 }
}


char buf[MAX] is not recognized as a buffer of fixed lenght on MSVC v9.0
whereas clearly it is.

Does that cause a compiler failure ? Even gcc 2.95 handles that.


yes
eg  jay.c is
----------
int     main(void)
{
const int n=10;
long a[n];
return 0;}
------------

cl jay.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

jay.c
jay.c(4) : error C2057: expected constant expression
jay.c(4) : error C2466: cannot allocate an array of constant size 0
jay.c(4) : error C2133: 'a' : unknown size

I'm not sure what to suggest for this , perhaps a

#define MAX 21

or

char buf[21] ;
chat *p=buf+sizeof(buf)/sizeof(buf[0]);

The second seems better (because it is more localized).

Cheers,
Bill.