Yeah, we need to be careful about variable size arrays - they are generally 
non-portable due to poor adoption of C99...

On Dec 30, 2010, at 4:20 AM, Greg Ercolano wrote:

> 
>       Thanks for the patch.
>       Your fix to Fl_PostScript should *definitely* be included in 1.3.0.
> 
>> There was also a problem in Fl_Postscript that wouldn't compile with
>> Visual C++ 2010 - it is resolved in the patch also.
> 
> --- src/Fl_PostScript.cxx     (revision 8140)
> +++ src/Fl_PostScript.cxx     (working copy)
> [..]
> -  unsigned unis[n + 1];
> -  char out[n + 1];
> +  unsigned int *unis = new unsigned int[n + 1];
> +  char *out = new char[n + 1];
> [..]
> +  delete [] unis;
> +  delete [] out;
> [..]
> 
>       These variable sized arrays were added recently in r8127:
>       http://fltk.org/newsgroups.php?gfltk.commit+v:8533
> 
>       Interesting.. runtime variable array sizes.
>       I wouldn't have thought the compilers would allow it, but
>       g++ seems to allow this C99 construction, VS (C89?) does not:
> 
> LINUX
> ----------------------------------------------------------
> % cat foo.cxx
> #include <stdio.h>
> int main() {
>    int n; scanf("%d", &n);
>    char s[n];
>    printf("sizeof(s): %d\n", sizeof(s));
> }
> 
> % g++ foo.cxx -o foo
> 
> % echo 133 | ./foo
> sizeof(s): 133
> 
> % echo 5000 | ./foo
> sizeof(s): 5000
> ----------------------------------------------------------
> 
> 
> VS 2010 and VS 2008
> ----------------------------------------------------------
> Z:\tmp>type foo.cxx
> #include <stdio.h>
> int main() {
>    int n;
>    scanf("%d", &n);
>    char s[n];
>    printf("sizeof(s): %d\n", sizeof(s));
> }
> 
> Z:\tmp>cl /TP foo.cxx
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 
> 80x86
> Copyright (C) Microsoft Corporation.  All rights reserved.
> 
> foo.cxx
> foo.cxx(5) : error C2057: expected constant expression
> foo.cxx(5) : error C2466: cannot allocate an array of constant size 0
> foo.cxx(5) : error C2133: 's' : unknown size
> foo.cxx(6) : error C2070: 'char []': illegal sizeof operand
> ----------------------------------------------------------
> _______________________________________________
> fltk-dev mailing list
> [email protected]
> http://lists.easysw.com/mailman/listinfo/fltk-dev

________________________________________
Michael Sweet, Easy Software Products

_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to