0

I am implementing a C preprocessor in C...

I have the three functions:

  1. trigraph replacing function
  2. Line splicing function
  3. comment removing function

However these functions work separately on files i.e.

First function will take a file and replace the trigraphs producing a temp-file1 as output

Second function will take temp-file1 as input and splice the lines and produce another temp-file2.

Third function will take temp-file2 as input and remove comment and produce yet another temp-file3.

And now the main preprocessing tasks will be performed on temp-file3 and a .i file will be produced as final output.

Now, I have 3 options :

  1. Use temp files
  2. use pipes
  3. instead of intermediate temp-files or pipes use strings(i.e. whole temp-file1, 2 and 3 will be three big strings!!)

I have three doubts...

  1. Option 1 seems less efficient than option2
  2. option 2 seems to be perfect but will I be limited by size of that unnamed pipe? (since I have single process i.e. function 1 2 & 3 will be called one after another) What if temp output size > pipe's total capacity?
  3. option 3... Is it efficient, easy over previous two?

Please tell me, Which option should I choose?

4

1 回答 1

0

我相信选项 2 是一些 C 编译器的实现方式:C 预处理器通过管道连接到 C 编译器,后者通过管道连接到汇编器。管道缓冲区的大小不是问题,因为进程是并发运行的,而不是顺序运行的。管道在生产者-消费者关系中实现了传统的 FIFO 队列。

于 2013-03-28T04:34:33.360 回答