C模拟数字信号时钟
#include<stdio.h>
#include<Windows.h>
#include"unistd.h"
#define REGS_FOREACH(_) _(X) _(Y)
#define RUN_LOGIC X1 = !X && Y; \
Y1 = !X && !Y;
#define DEFINE(X) static int X, X##1;
#define UPDATE(X) X = X##1;
#define PRINT(X) printf(#X " = %d; ", X);
int main()
{
REGS_FOREACH(DEFINE);
while (1) { //clock
RUN_LOGIC;
REGS_FOREACH(PRINT);
REGS_FOREACH(UPDATE);
putchar('\n');
Sleep(1000);
}
}
只激活预处理,把它重定向到pre.txt中
gcc -E clock.cpp > pre.txt
宏展开为👇
参考GCC 参数详解 | 菜鸟教程 (runoob.com)https://www.runoob.com/w3cnote/gcc-parameter-detail.html
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/16074858.html