Pelles C forum

Pelles C => Bug reports => Topic started by: BFG10K on April 07, 2025, 02:57:16 PM

Title: Compound literals can't be used as default parameters
Post by: BFG10K on April 07, 2025, 02:57:16 PM
Since default parameters aren't standard C, I'm unsure if this is a bug or intended.

It'd be really nice if it worked, so we can pass default arrays into functions.

void function( int* param = ( int[] ){ 1, 2, 3 } ){ //This doesn't work
 int* local = ( int[] ){ 1, 2, 3 }; //This works
}
Title: Re: Compound literals can't be used as default parameters
Post by: TimoVJL on April 07, 2025, 04:43:38 PM
Reading this might help
https://web.cs.dal.ca/~vlado/pl/C_Standard_2011-n1570.pdf (https://web.cs.dal.ca/~vlado/pl/C_Standard_2011-n1570.pdf)
https://www.iso-9899.info/wiki/The_Standard (https://www.iso-9899.info/wiki/The_Standard)
Title: Re: Compound literals can't be used as default parameters
Post by: BFG10K on April 08, 2025, 12:35:23 PM
Quote from: TimoVJL on April 07, 2025, 04:43:38 PMReading this might help
No, nothing to do with the /Zx compiler switch.
Title: Re: Compound literals can't be used as default parameters
Post by: TimoVJL on April 08, 2025, 01:24:59 PM
>gcc -c test_Zx.c
test_Zx.c:1:27: error: expected ';', ',' or ')' before '=' token
    1 | ´╗┐void function( int* param = ( int[] ){ 1, 2, 3 } ){ //This doesn't work