質問

スパースの経験はありますか?私はドキュメントを見つけることができないようですので、警告とそれが生成するエラーは私にはわかりません。メーリングリストとマニュアルページを確認してみましたが、実際にはあまりありません。

たとえば、ファイルの1つでINT_MAXを使用します。 limits.hを#includeしても、これによりエラー(未定義識別子)が生成されます。

エラーと警告が説明されている場所はありますか?

役に立ちましたか?

解決

スパースは、リントを意図したものではありません。スパースは、任意のコードの解析ツリーを生成して、さらに分析できるようにすることを目的としています。

あなたの例では、GNU_SOURCE(__GNUC__をオンにしていると思います)を定義します。これは、limits.hで必要なビットを公開します

__ GNUC__を単独で定義することは避けます。GNU_SOURCEがオンにする他のすべてのスイッチが定義されていなくても、それがアクティブにするいくつかのことは未定義の方法で動作する可能性があるからです。

私が言いたいのは、エラーごとにエラーをつぶすことではなく、スパースはスタンドアロンの静的解析ツールとしてではなく、ライブラリとして主に使用されることを繰り返し述べます。

READMEのコピーから(現在のバージョンがあるかどうかわからない):

This means that a user of the library will literally just need to do

  struct string_list *filelist = NULL;
  char *file;

  action(sparse_initialize(argc, argv, filelist));

  FOR_EACH_PTR_NOTAG(filelist, file) {
    action(sparse(file));
  } END_FOR_EACH_PTR_NOTAG(file);

and he is now done - having a full C parse of the file he opened.  The
library doesn't need any more setup, and once done does not impose any
more requirements.  The user is free to do whatever he wants with the
parse tree that got built up, and needs not worry about the library ever
again.  There is no extra state, there are no parser callbacks, there is
only the parse tree that is described by the header files. The action
function takes a pointer to a symbol_list and does whatever it likes with it.

The library also contains (as an example user) a few clients that do the
preprocessing, parsing and type evaluation and just print out the
results.  These clients were done to verify and debug the library, and
also as trivial examples of what you can do with the parse tree once it
is formed, so that users can see how the tree is organized.

含まれているクライアントは、何よりも「機能テストスイートとサンプル」です。これは非常に便利なツールですが、使用する場合は別の使用方法を検討してください。 * lex / bisonを使用しないため、ハッキングが非常に簡単になります。

他のヒント

limits.hを見ると、INT_MAXがこの#if内で定義されていることがわかります

/* If we are not using GNU CC we have to define all the symbols ourself.
 Otherwise use gcc's definitions (see below).  */
#if !defined __GNUC__ || __GNUC__ < 2

そのため、制限を含める前に __ GNUC __ の定義を解除する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top