删除由cpp生成的注释 [英] Remove the comments generated by cpp
问题描述
在 lexer.mll
中使用 #include... / frontend / tokens.mll
,以及然后 cpp -C -P frontend / lexer.mll -o frontend / lexer_new.mll
来生成 lexer_new.mll
。
直到昨天将我的ubuntu从12.04升级到14.04为止。
编译出错:
ocamllex frontend / lexer_new.mll
文件frontend / lexer_new.mll,第1行,字符1:非法字符/。
make:*** [frontend / lexer_new.ml]错误3
这是因为在 lexer_new.mll
开始处插入了几行C注释:
/ * Copyright(C)1991-2014 Free Software Foundation,Inc.
本文件是GNU C库的一部分。
GNU C库是免费软件;您可以根据自由软件基金会发布的GNU Lesser General Public
许可条款对其进行重新分配和/或
修改;许可证的
版本2.1,或者(根据您的选择)任何更新的版本。
... * /
我不记得升级前是否有相同的评论。
有人知道如何获得这些评论吗?
PS:gcc版本是: gcc version 4.8.2(Ubuntu 4.8.2-19ubuntu1)
忽略 -C
选项会阻止插入的版权信息。
从 ' - C ' 您应该在使用'-C'时为副作用做好准备;它导致 源代码中的注释在默认情况下被丢弃。 这个可能有其他效果,好或坏。如果 更多信息:跑步 表示版权评论来自 ( 你为什么在非C代码中使用 I use That worked until I upgraded my ubuntu from 12.04 to 14.04 yesterday. The compilation gives an error: That is because in I don't remember if same comments were generated before upgrading. Does anyone know how to get ride of these comments? PS: the gcc version is : Omitting the From the documentation: '-C' 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 This might have other effects, good or bad. If More information: running indicates that the copyright comment comes from (The Why were you using 这篇关于删除由cpp生成的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
不要丢弃评论。所有注释都会传递到
输出文件,除了已处理的指令中的注释(
和指令一起被删除)。
预处理器将注释视为自己的权利。
例如,出现在
指令行开头的注释会将该行转换为
的普通源代码行,因为该行上的第一个标记不是
加一个'#'。
-C
选项使它们通过。显然,在最近的版本中,它也插入了版权信息。
-C
之前为你工作,那么OCaml代码中看起来像C注释的东西可能是从
lexer.mll
至 lexer_new.mll
;省略 -C
会导致它们被删除。如果这是一个问题,您可能需要保留 -C
选项,并在删除添加的注释的预处理器之后添加一个过滤器。 (写这样的过滤器留作练习。)
cpp -C / dev / null
/usr/include/stdc-predef.h
:
$ cpp -C / dev / null
#1/ dev / null
#1< command-line>
#1/usr/include/stdc-predef.h1 3 4
/ * Copyright(C)1991-2014 Free Software Foundation,Inc.
此文件是GNU C库。
[39行删除]
#1/ dev / null
$
-P
选项禁止显示文本出处的#
指令。)显然,在预处理C源文件时默认包含该文件。它定义了一些特定于C的预定义宏,比如 __ STDC_IEC_559 __
和 __ STDC_ISO_10646 __
。
-C
?#include ".../frontend/tokens.mll"
in lexer.mll
, and then cpp -C -P frontend/lexer.mll -o frontend/lexer_new.mll
to generate lexer_new.mll
.ocamllex frontend/lexer_new.mll
File "frontend/lexer_new.mll", line 1, character 1: illegal character /.
make: *** [frontend/lexer_new.ml] Error 3
lexer_new.mll
several lines of C comments have been inserted in the beginning:/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
... */
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
-C
option appears to inhibit the inserted copyright message.
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.-C
option causes them to be passed through. Apparently in recent versions it also inserts that copyright message.-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.)cpp -C /dev/null
/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"
$
-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__
.-C
for non-C code?