Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
39 Views

Variable lenght array

Hi all!

Although this code has many features that are strictly forbidden by the C standard I think most of them are supported as Intel extensions.

#include <stdlib.h>
#include <stdio.h>

#if defined(RANK)
#define IRANK RANK
#else
#define IRANK 0
#endif

#define MSTRUCT(r) struct{int dim;}

int main(int argc, char **argv){
  int        n = IRANK;
  MSTRUCT(n) s;
 
  printf("%zu, %zu\n", sizeof(s), sizeof(MSTRUCT(n)));
  return EXIT_SUCCESS;
}

I would expect the code to print two identical numbers.

Using -ftrapuv changes the value printed, -O0 had the same effect on a more complicated variation.

Thank you very much.

Best regards,

José Rui

 

0 Kudos
3 Replies
Highlighted
Moderator
39 Views

This code has an uninitialized variable "int dim[0];" which can lead to undefined behavior.

0 Kudos
Highlighted
Moderator
39 Views

I meant is "variable length array" not "uninitialized variable"

0 Kudos
Highlighted
39 Views

Yes, the code has several features that are not standard conforming, but I think that some of them are supported by Intel as extensions.

Thank you very much.

Best regards,

José Rui

 

0 Kudos