gbranden pushed a commit to branch master
in repository groff.
commit def970ba8a91435d979c895716162c2f62261d1f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 16 14:32:00 2026 -0600
src/preproc/pic/lex.cpp: Fix code style nit.
* src/preproc/pic/lex.cpp (yylex): Return zero of character type (`\0`)
rather than integer. The idiomatic use of lex/flex is deliberately
slovenly typed, assuming a 7- or 8-bit character type and package a
bunch of integral token identifiers into the copious headroom in an
`int` beyond the range of a valid `char`. Nothing bad could possibly
happen when your fundamental character type is actually wider and has
values that collide with your token identifiers, which could have been
in an `enum` but aren't. Real Programmers don't need data types. At
any rate I intend this change to help the reader grasp that the `0`
literal here is not a null pointer constant, which it idiomatically
can be in ISO C++98.
---
ChangeLog | 15 +++++++++++++++
src/preproc/pic/lex.cpp | 7 ++++---
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fb68ed7c9..0ca9cf044 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2026-11-16 G. Branden Robinson <[email protected]>
+
+ * src/preproc/pic/lex.cpp (yylex): Fix code style nit. Return
+ zero of character type (`\0`) rather than integer. The
+ idiomatic use of lex/flex is deliberately slovenly typed,
+ assuming a 7- or 8-bit character type and package a bunch of
+ integral token identifiers into the copious headroom in an `int`
+ beyond the range of a valid `char`. Nothing bad could possibly
+ happen when your fundamental character type is actually wider
+ and has values that collide with your token identifiers, which
+ could have been in an `enum` but aren't. Real Programmers don't
+ need data types. At any rate I intend this change to help the
+ reader grasp that the `0` literal here is not a null pointer
+ constant, which it idiomatically can be in ISO C++98.
+
2026-11-16 G. Branden Robinson <[email protected]>
* src/preproc/pic/lex.cpp: Fix code style nits. Drop names of
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
index 4337d318a..9533303a2 100644
--- a/src/preproc/pic/lex.cpp
+++ b/src/preproc/pic/lex.cpp
@@ -1872,6 +1872,7 @@ void do_lookahead()
extern int yylex();
+// Return a character or integer-encoded token identifier.
int yylex()
{
if (delim_flag) {
@@ -1880,7 +1881,7 @@ int yylex()
if ((yylval.str = get_thru_arg()) != 0)
return DELIMITED;
else
- return 0;
+ return '\0';
}
else {
if (get_delimited()) {
@@ -1889,7 +1890,7 @@ int yylex()
return DELIMITED;
}
else
- return 0;
+ return '\0';
}
}
for (;;) {
@@ -1904,7 +1905,7 @@ int yylex()
case '\n':
return ';';
case EOF:
- return 0;
+ return '\0';
case DEFINE:
do_define();
break;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit