[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Conflicts with header guards

From: Akim Demaille
Subject: Conflicts with header guards
Date: Fri, 21 Sep 2012 11:42:55 +0200

Currently, there is no provision on the header guards
that we generate: they are "<PREFIX>_<FILENAME>" where PREFIX
and FILENAME are the upper-cased versions of the prefix and
filename, with series of non-letters/digits mapped to _.  So:

   foo/bar.hh    -> YY_FOO_BAR_HH
   0foo--bar12.h -> YY_0FOO_BAR12_H

but I should have anticipated that we may have collisions with
symbols used by Bison:

$ git grep '# *define *YY_' data |
 perl -ne '
  /^(.*?):# *define *(YY_\w+)/ and $names{$2}->{$1}++;
  END { print "$_ => @{[%{$names{$_}}]}\n" foreach sort keys %names};
YY_LAC_DISCARD => data/yacc.c 2
YY_LAC_ESTABLISH => data/yacc.c 1
YY_LOCATION_PRINT => data/yacc.c 3 data/glr.c 2
YY_NULL => data/c.m4 2
YY_REDUCE_PRINT => data/lalr1.cc 2 data/yacc.c 2 data/glr.c 2
YY_RESERVE_GLRSTACK => data/glr.c 2
YY_STACK_PRINT => data/lalr1.cc 2 data/yacc.c 2
YY_SYMBOL_PRINT => data/lalr1.cc 2 data/yacc.c 2 data/glr.c 2

So with --defines=symbol/print for instance, we use
YY_SYMBOL_PRINT as a guard and get a collision.  Very unlikely,
but useless risk.

We can also get collisions with other symbols:

$ bison -p exit --defines=success foo.y
$ grep EXIT_SUCCESS success
#endif /* !EXIT_SUCCESS  */

What would you recommend?  AFAICT, there is no way to avoid
completely the problem, but we should at least always start
with YY_ to stay within our realm:

   foo/bar.hh    -> YY_YY_FOO_BAR_HH
   0foo--bar12.h -> YY_YY_0FOO_BAR12_H

(two YY_: one for Bison, the other for the prefix), and
maybe always append an _ (as seems to be the convention
in gnulib), or _INCLUDED.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]