Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Variable lenght array

faustino_de_sousa__j
481 Views

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
Viet_H_Intel
Moderator
481 Views

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

0 Kudos
Viet_H_Intel
Moderator
481 Views

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

0 Kudos
faustino_de_sousa__j
481 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
Reply