The macro name is MAX_SIZE and it is abbreviated for the constant 1000. From now on, you can use this macro “like” an identifier in code such as:

Advanced illuminationRing Light

In the code, the preprocessor only replaces function-like macro when the macro name appears with the parentheses () right after it.

Image

Summary: in this tutorial, you will learn about C macro. We will show you two different kinds of macros in C including object-like macros and function-like macros.

Advanced illumination vtapp

A C macro is a piece of code that has a specific name called macro name. Whenever the macro name is used, C preprocessor will replace it with the body of the macro. C allows you to define a macro for any valid identifier, even C keyword.

Advanced illuminationbacklight

Image

Advanced IlluminationDistributors

C also allows you to define a macro that look like a function call. Therefore, this macro is referred as a function-like macro.

You can define a macro onto multiple lines using backslash-newline. C preprocessor will treat it as one line when the macro is expanded, for example:

In this tutorial, you have learned how to create two different kinds of macros in C: object-like macro and function-like macro. It is important to use C macro properly to increase your code readability.

Another important point you should keep in mind that C preprocessor processes program sequentially. Therefore, the macro is effective from the position where it is defined. Consider the following example:

The syntax of creating a function-like macro is similar to object-like macro except you have to put the parentheses () right after the macro name.

Advanced illumination vtprice

An object-like macro is an identifier that will be replaced by a sequence of token ( or piece of code) in the program. As its name implied, the object-like macro is similar to data object in code in term of its usage. You typically use an object-like macro to give a meaningful name to a constant.

Image