Compound literals can't be used as default parameters

Started by BFG10K, April 07, 2025, 02:57:16 PM

Previous topic - Next topic

BFG10K

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
}

TimoVJL

May the source be with you

BFG10K


TimoVJL

>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
May the source be with you