What do .c and .h file extensions mean to C?

前端 未结 6 1587
有刺的猬
有刺的猬 2020-12-04 08:29

It\'s all in the title; super-simple I reckon, but it\'s so hard to search for syntactical things anywhere.

These are two library files that I\'m copying from CS50.n

6条回答
  •  臣服心动
    2020-12-04 08:41

    Of course, there is nothing that says the extension of a header file must be .h and the extension of a C source file must be .c. These are useful conventions.

    E:\Temp> type my.interface
    #ifndef MY_INTERFACE_INCLUDED
    #define MYBUFFERSIZE 8
    #define MY_INTERFACE_INCLUDED
    #endif
    
    E:\Temp> type my.source
    #include 
    
    #include "my.interface"
    
    int main(void) {
        char x[MYBUFFERSIZE] = {0};
        x[0] = 'a';
        puts(x);
        return 0;
    }
    
    E:\Temp> gcc -x c my.source -o my.exe
    
    E:\Temp> my
    a
    

提交回复
热议问题