NO

Author Topic: Variable-Sized Array Internal Error  (Read 3123 times)

Armin

  • Guest
Variable-Sized Array Internal Error
« on: April 19, 2013, 09:25:24 AM »
This code produces an error in Pelles:  "fatal error: Internal error: liveness_usesite()."
Code: [Select]
#include <stdio.h>

int len1;
int len2;

void testFunction(char [len1][len2] );

void testFunction(char arr[len1][len2] )    //issue is here with char arr[len1][len2]
{
printf("%s" , arr[len1-1] ) ;
}

int main(int argc,char *argv[])
{
len1 = 10 ;
len2 = 20 ;

char array[len1][len2] ;

array[len1-1][0] = 'a' ;
array[len1-1][1] = '\0' ;

testFunction( array ) ;

    return 0;
}
Yet this code compiles on gcc: "gcc -Wall -std=c99 -lm filename.c" and on http://ideone.com/iAEXpg and a couple of other compilers, without any errors or warnings and displays the correct output ( a ).

Only pelles displays this error.
Removing len2 from function and changing the parameter to a 1d array removes the error.

Im using the latest pelles version, code was tested on a new project (Windows 32 console exe), with default settings.



EDIT:
A more compact version of the problem
Code: [Select]
int len;

void testFunction(char arr[][len] )
{
}

int main(int argc,char *argv[])
{
return 0;
}
Again all other compilers agree this is correct http://ideone.com/l4sqqj,
but pelles displays "main.c(4): fatal error: Internal error: liveness_usesite()."


EDIT 2:

Works correctly on 1D array

Code: [Select]
int len ;

void testFunction(char arr[len] )
{
}

int main(int argc,char *argv[])
{
return 0;
}
« Last Edit: April 20, 2013, 04:40:14 PM by Stefan Pendl »

player55

  • Guest
Re: Variable-Sized Array Internal Error
« Reply #1 on: April 20, 2013, 12:41:29 PM »
It is better to use #define for array sizes. Example:

Code: [Select]
#define LEN 5
« Last Edit: April 20, 2013, 12:49:16 PM by player55 »

Armin

  • Guest
Re: Variable-Sized Array Internal Error
« Reply #2 on: April 20, 2013, 03:27:54 PM »
It is better to use #define for array sizes. Example:
Great, but i have posted a specific problem about a pelles bug, your suggestion does not approach it.


« Last Edit: April 20, 2013, 03:49:33 PM by Armin »