Search code examples
csyntaxoperating-systemclangosdev

Is it possible to define keywords in C


i am currently looking at the HarmonyOS source code, and I can up with a problem. In the image I know that the function doesn't return anything, but what's the LITE_OS_SEC_TEXT part? I havent seen this keyword before, or is it even a keyword like STATIC or typedef. And if so, how do you define a keyword in C?

Picture


Solution

  • how do you define a keyword in C?

    You don't. It's impossible.

    What you can do is to use macros. They are basically just advanced text replacement. The preprocessor is run before the compiler. That is, in principal. On modern compilers they are run at the same time, but the behavior is the same.

    If you want to look at the source code after the preprocessor, you can use the -E parameter to the compiler.

    Here is an example of how you can make C code more like Pascal. DON'T DO THIS! JUST FOR FUN!

    #include <stdio.h>
    
    #define Begin {
    #define End ;}
    #define Writeln(X) puts(X)
    
    int main(void)
    Begin
        Writeln("Hello, World!");
        Writeln("Hello again")
    End