constant.h文件内容:
static const char test_static_variable = 'a';
function_module.c文件内容:
#ifndef __STDIO_H #define __STDIO_H #include <stdio.h> #endif #ifndef __CONSTANT_H #define __CONSTANT_H #include "constant.h" #endif void test(void) { printf("from test function a:%c\r\n", test_static_variable); }
main.c文件内容:
#ifndef __STDIO_H #define __STDIO_H #include <stdio.h> #endif #ifndef __STRING_ #define __STRING_H #include <string.h> #endif #ifndef __DIRENT_H #define __DIRENT_H #include <dirent.h> #endif #ifndef __STDLIB_H #define __STDLIB_H #include <stdlib.h> #endif #ifndef __CONSTANT_H #define __CONSTANT_H #include "constant.h" #endif void test(); int main(char argc, char* argv) { int age = 31; int score = 92; const int* p = &age;//const修饰的*p int* const p1 = &age;//const修饰的p1 //*p += 1;//不合法 p = &score; //p1 = &score;//不合法 *p1 += 1; printf("%2d\r\n", *p); printf("%2d\r\n", *p1); printf("from main function a:%c\r\n", test_static_variable); test(); return 0x00; }
标签:__,include,定义,C语言,test,endif,ifndef,全局变量,define From: https://www.cnblogs.com/JianfeiMa/p/18311595