如何在编译期间写程序? [英] How to write program during compiling?
本文介绍了如何在编译期间写程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
写一个小的C程序,该程序在编译时需要另一个程序
从输入端子,并在运行给出第二结果
程序。 (注:最关键的是,认为UNIX)
假设,程序1.C
然后,在编译
$ CC -o 1 1.C
诠释的main()
{
的printf(的Hello World \\ n);
}
^ D
$ ./1
你好,世界
$
解决方案
这是一个老把戏parlaour我猜
我的程序,tty.c:
的#include的/ dev / tty的
壳牌:
$ GCC tty.c
诠释主(){
的printf(嘿\\ n);
} *按Ctrl-D这里*
1:在文件从tty.c包括:
为/ dev / tty的:在函数'主':
为/ dev / tty的:2:警告:内建函数'printf的不兼容的隐式声明
$。/ a.out的
嘿
Write a small C program, which while compiling takes another program from input terminal, and on running gives the result for the second program. (NOTE: The key is, think UNIX).
Suppose, the program is 1.c Then, while compiling
$ cc -o 1 1.c
int main()
{
printf("Hello World\n");
}
^D
$ ./1
Hello World
$
解决方案
This is an old parlaour trick I guess
My program, tty.c:
#include "/dev/tty"
Shell:
$ gcc tty.c
int main() {
printf("Hey\n");
} *Ctrl-D here*
In file included from tty.c:1:
/dev/tty: In function ‘main’:
/dev/tty:2: warning: incompatible implicit declaration of built-in function ‘printf’
$./a.out
Hey
这篇关于如何在编译期间写程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文