Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Variable lenght array

faustino_de_sousa__j
206 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
206 Views

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

Viet_H_Intel
Moderator
206 Views

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

faustino_de_sousa__j
206 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

 

Reply