Remove the comments generated by cpp

笑着哭i 提交于 2019-12-05 18:17:42

Omitting the -C option appears to inhibit the inserted copyright message.

From the documentation:

'-C'
Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.

You should be prepared for side effects when using '-C'; it causes the preprocessor to treat comments as tokens in their own right. For example, comments appearing at the start of what would be a directive line have the effect of turning that line into an ordinary source line, since the first token on the line is no longer a '#'.

Comments in the source code are discarded by default. The -C option causes them to be passed through. Apparently in recent versions it also inserts that copyright message.

This might have other effects, good or bad. If -C was working for you before, it may be that some things that looked like C comments in your OCaml code were being passed through from lexer.mll to lexer_new.mll; omitting -C would cause them to be removed. If that's an issue, you might want to keep the -C option and add a filter after the preprocessor that removes the added comment. (Writing such a filter is left as an exercise.)

More information: running

cpp -C /dev/null

indicates that the copyright comment comes from /usr/include/stdc-predef.h:

$ cpp -C /dev/null
# 1 "/dev/null"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
[39 lines deleted]
# 1 "/dev/null"
$

(The -P option was inhibiting the # directives that indicate where the text came from.) Apparently that file is included by default when preprocessing C source. It defines a few C-specific predefined macros such as __STDC_IEC_559__ and __STDC_ISO_10646__.

Why were you using -C for non-C code?

DonMorton

I ran into this problem recently (it was actually more complex, but boiled down to these issues), and described it and its solution in CPP/GPP in Fortran variadic macro (plus Fortran // concatenation)

In short, the fix was to install an older version of cpp, which I learned can be done easily without having to use a previous version of the compiler.

On ubuntu 16.04

sudo apt-get install cpp-4.7

and then use

/usr/bin/cpp-4.7 -C -P myfile.F90 > myfile.f90

You can use cpp with flag -nostdinc and do not use flag -C.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!