Simple use of 005 gcc

0. Introduction

  • This article speaks several ways to compile on gcc,
  • You may wish to set up a file called test.c

1. A method

$ gcc test.c
  • (Windows OS) compiler successful, there is no feedback, in test.ccase the folder where you will add aa.exe
  • Operation method: to a respective path, choose one of the following
    • .\a.exe
    • a.exe

2. Method Two

2.1 a written

$ gcc -o test test.c

2.2 writing two

$ gcc test.c -o test
  • As the effect of two kinds of writing
  • If successful, the test.cnext folder where you will add atest.exe

3. Method Three

3.1 a written

$ gcc -std=c99 -o test test.c

3.2 writing two

$ gcc -std=c99 test.c -o test
  • As the effect of two kinds of writing
  • The wording specified C Standard: C99, to specify other criteria, can be -std=xxx

4. About C99

  • Simply give an example
#include <stdio.h>

int main()
{
    int a[13] = {[1]=2, 4, [5]=6};  // C99 的特性,定义数组时可以指定特定的位置
    
    for(int i=0; i<13; i++)         // C11 可用,ANSI C 不行
    {
        printf("a[%d] = %d\n", i, a[i]);
    }
    
    return 0;
}
$ gcc test.c -o test            // 会报错
$ gcc -std=c99 test.c -o test   // 这样才行

Guess you like

Origin www.cnblogs.com/yorkyu/p/11441064.html