Skip to content

Instantly share code, notes, and snippets.

@iwadon
Last active December 15, 2015 10:09
Show Gist options
  • Select an option

  • Save iwadon/5243888 to your computer and use it in GitHub Desktop.

Select an option

Save iwadon/5243888 to your computer and use it in GitHub Desktop.
Visual Studio 2012 for Windows Desktopで配列の添字を省略できるかどうかを確認してみた。 →[]でも[0]でも結果は変わらず。
#include <stdio.h>
#include <stdlib.h>
struct A
{
int i[];
};
int main(int argc, char *argv[])
{
struct A *a = malloc(sizeof (struct A) + sizeof (int) * 3);
a->i[0] = 0;
a->i[1] = 1;
a->i[2] = 2;
printf("%d %d %d\n", a->i[0], a->i[1], a->i[2]);
free(a);
return 0;
}
>cl a.c
Microsoft(R) C/C++ Optimizing Compiler Version 17.00.60204.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
a.c
Microsoft (R) Incremental Linker Version 11.00.60204.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:a.exe
a.obj
>a.exe
0 1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment