From 8d2aaee31b3b394b9c987f7f7ec245964f2deace Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Tue, 9 Aug 2022 11:15:08 +0100 Subject: Add macro --- md/notes/undefined_c/titles.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'md/notes/undefined_c/titles.md') diff --git a/md/notes/undefined_c/titles.md b/md/notes/undefined_c/titles.md index 92b35ab..0108449 100644 --- a/md/notes/undefined_c/titles.md +++ b/md/notes/undefined_c/titles.md @@ -282,7 +282,41 @@ ulimit -s 16384 ### Macro +There is many things useful as macros. There is many tricks in macros to emit +useful parts of code. +Define values, as its enum. +```c +#define VAL_0 0 +#define VAL_1 1 +#define VAL_LAST VAL_1 +``` + +Multiline macro +```c +#define INC_FUN(TYPE) TYPE inc_##TYPE(a TYPE){\ + TYPE c=1\ + return a + c\ +} + +INC_FUN(int) +INC_FUN(char) +INC_FUN(double) +INC_FUN(notype) +``` + +to check code expansion of macro run + +``` +gcc -E +``` + + + +http://main.lv/writeup/c_macro_tricks.md + + +https://jadlevesque.github.io/PPMP-Iceberg/ ### Signed/Unsigned ### Pointers -- cgit v1.2.3