arrays - Why is int a[0] allowed in c++? -


this question has answer here:

i find in declaration of array, cannot specify size of this

int a[0]; 

i know, empty size array illegal in c++, in code, empty size array compiler allowed , give output.

my code here :

#include <iostream> using namespace std;  int main() {         int a[0];          a[0] = 10;         a[1] = 20;          cout<<a[0]<<endl;         cout<<a[1]<<endl;          return 0; } 

output:

10 20 

online compiler link : http://code.geeksforgeeks.org/tteomo

so, question is, why int a[0] allowed gcc compiler?

it issues warning, example clang outputs:

warning: 0 size arrays extension [-wzero-length-array] 

this undefined behaviour:

    a[0] = 10;     a[1] = 20; 

zero length arrays extensions gcc, why - can read on here:

https://gcc.gnu.org/onlinedocs/gcc/zero-length.html

they useful last element of structure header variable-length object:

this c extension looks used in c++, make easier use existing structures c uses extension.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -