C’s predefined macros

C's predefined macros
A list of C's predefined macros (__FILE__, __LINE__, __STDC__...) with description and an example of how to use them.

__FILE__ – a string that holds the path/name of the compiled file;
__LINE__ – an integer that holds the number of the current line number;
__DATE__ – a string that holds the current system date;
__TIME__ – a string that holds the current system time;
__STDC__ – defined as the value ‘1’ if the compiler conforms with the ANSI C standard;
__cplusplus – determines if your compiler is in C or C++ mode. Usually used in headers.

#include <stdio.h>

void main(void)
    printf(“The path/name of this file is %s\n”, __FILE__);
    printf(“The current line is %d\n”, __LINE__);
    printf(“The current system date is %s\n”, __DATE__);
    printf(“The current system time is %s\n”, __TIME__);
    #ifdef __STDC__
        printf(“The compiler conforms with the ANSI C standard\n”);
        printf(“The compiler doesn’t conform with the ANSI C standard\n”);
    #ifdef __cplusplus
        printf(“The compiler is working with C++\n”);
        printf(“The compiler is working with C\n”);

Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top