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)icon-default.png?t=M276https://www.runoob.com/w3cnote/gcc-parameter-detail.html 

posted @ 2022-03-30 08:50  泥烟  阅读(214)  评论(0编辑  收藏  举报