diff options
| author | Linus Torvalds <torvalds@home.osdl.org> | 2003-07-18 19:07:03 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:00:56 -0700 |
| commit | 95e1e20937a430ab9f5fac6daf7a41a7ec55b524 (patch) | |
| tree | edc96408d20ee71d1ae6ce1cd46af4491f0052da | |
| parent | 10e9653b49d81800837f1e7c8ea39039cb32a27f (diff) | |
| download | sparse-dev-95e1e20937a430ab9f5fac6daf7a41a7ec55b524.tar.gz | |
More preprocessor validation tests from comp.std.c.
One is interesting (preprocessor3.c), and we get it wrong.
Surprise surprise.
| -rw-r--r-- | validation/preprocessor3.c | 37 | ||||
| -rw-r--r-- | validation/preprocessor4.c | 10 | ||||
| -rw-r--r-- | validation/preprocessor5.c | 9 |
3 files changed, 56 insertions, 0 deletions
diff --git a/validation/preprocessor3.c b/validation/preprocessor3.c new file mode 100644 index 00000000..71b9acde --- /dev/null +++ b/validation/preprocessor3.c @@ -0,0 +1,37 @@ +/* + * We get this one wrong too. + * + * It should result in a sequence + * + * B ( ) + * A ( ) + * B ( ) + * A ( ) + * + * because each iteration of the scanning of "SCAN()" + * should re-evaluate the recursive B->A->B expansion. + * But we never re-evaluate something that we noticed + * was recursive. So we will cause it to evaluate to + * + * B ( ) + * A ( ) + * A ( ) + * A ( ) + * + * Which is really quite wrong. + * + * Did I already mention that the C preprocessor language + * is a perverse thing? + */ + +#define LP ( + +#define A() B LP ) +#define B() A LP ) + +#define SCAN(x) x + +A() // B ( ) +SCAN( A() ) // A ( ) +SCAN(SCAN( A() )) // B ( ) +SCAN(SCAN(SCAN( A() ))) // A ( ) diff --git a/validation/preprocessor4.c b/validation/preprocessor4.c new file mode 100644 index 00000000..8b8c4da2 --- /dev/null +++ b/validation/preprocessor4.c @@ -0,0 +1,10 @@ +/* + * More examples from the comp.std.c discussion. + * + * This should result in bar(bar). We get it right. + */ +#define foo bar +#define mac(x) x(foo) + +mac(foo) + diff --git a/validation/preprocessor5.c b/validation/preprocessor5.c new file mode 100644 index 00000000..fa389376 --- /dev/null +++ b/validation/preprocessor5.c @@ -0,0 +1,9 @@ +/* + * Yet more examples from comp.std.c. + * + * This should result in "a|". We get it right. + */ +#define a a| +#define b(x) x + +b(a) |
