xprop.c:1291:10: error: expected identifier or ‘(’ before ‘true’
(Yay more fallout from C23! see previous one: xorg/lib/libxt#20 (closed) )
When I compile with -std=gnu2x I get the following
CC xprop.o xprop.c: In function ‘Handle_Question_Mark’: xprop.c:1291:10: error: expected identifier or ‘(’ before ‘true’ 1291 | long true; | ^~~~ xprop.c:1293:49: error: lvalue required as unary ‘&’ operand 1293 | dformat = Scan_Exp(dformat, thunks, format, &true); | ^ make[2]: *** [Makefile:507: xprop.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: Leaving directory '/sources/blfs/xorg-apps/xprop-1.2.6'
when i use the default std i do not. what is happening in xprop.c is that the newly as of C23 reserved word 'true' is being defined again, and that isn't working because it's not an identifier.
the good news: this variable 'true' is just in the local function Handle_Question_Mark () although it is used as a boolean value so realistically there's going to be 2 ways of solving this depending on the taste of you, the maintainer
option 1) the easy way
simply rename the value 'true' to a non-reserved word, like 't' like the fix in the previous case
the following patch does this
--- xprop-1.2.6/xprop.c 2022-12-03 16:32:26.000000000 -0600
+++ xprop-fixed/xprop.c 2023-11-13 18:51:00.409900543 -0600
@@ -1288,15 +1288,15 @@
static const char *
Handle_Question_Mark (const char *dformat, thunk *thunks, const char *format)
{
- long true;
+ long t;
- dformat = Scan_Exp(dformat, thunks, format, &true);
+ dformat = Scan_Exp(dformat, thunks, format, &t);
if (*dformat != '(')
Fatal_Error("Bad conditional: '(' expected: %s.", dformat);
++dformat;
- if (!true)
+ if (!t)
dformat = Skip_Past_Right_Paren(dformat);
return dformat;
option 2) do the same and also change Scan_Exp (and all of its callers both inside and outside of this program) to use C booleans if it's being compiled with C23 or above. Really Scan_Exp "returns" two values, one set of data and one boolean.
ok so option 2 has a snag that suggests an option 3, but let's get to the patch first:
this changes the Scan_Exp function to actually use a boolean if booleans are supported, and the above.
--- xprop-1.2.6/xprop.c 2022-12-03 16:32:26.000000000 -0600
+++ xprop-fixed/xprop.c 2023-11-13 19:07:52.545823882 -0600
@@ -1258,10 +1258,14 @@
return string;
}
+#if __STDC_VERSION__ >= 202311L
+static const char *
+Scan_Exp (const char *string, thunk *thunks, const char *format, boolean *value)
+#else
static const char *
Scan_Exp (const char *string, thunk *thunks, const char *format, long *value)
+#endif
{
- long temp;
if (string[0] == '(') {
string = Scan_Exp(++string, thunks, format, value);
@@ -1277,6 +1281,12 @@
string = Scan_Term(string, thunks, format, value);
+ #if __STDC_VERSION__ >= 202311L
+ boolean temp;
+ #else
+ long temp;
+ #endif
+
if (string[0] == '=') {
string = Scan_Exp(++string, thunks, format, &temp);
*value = *value == temp;
@@ -1285,18 +1295,23 @@
return string;
}
+
static const char *
Handle_Question_Mark (const char *dformat, thunk *thunks, const char *format)
{
- long true;
-
- dformat = Scan_Exp(dformat, thunks, format, &true);
+ #if __STDC_VERSION__ >= 202311L
+ boolean t;
+ #else
+ long t;
+ #endif
+
+ dformat = Scan_Exp(dformat, thunks, format, &t);
if (*dformat != '(')
Fatal_Error("Bad conditional: '(' expected: %s.", dformat);
++dformat;
- if (!true)
+ if (!t)
dformat = Skip_Past_Right_Paren(dformat);
return dformat;
BUT apparently this isn't C90 kosher now. I don't know if anyone cares about C90 but for the hell of it, i have googled some ideas of how to fix that . . .
--- xprop-1.2.6/xprop.c 2022-12-03 16:32:26.000000000 -0600
+++ xprop-fixed/xprop.c 2023-11-13 19:15:33.082789000 -0600
@@ -1258,10 +1258,22 @@
return string;
}
+#if __STDC_VERSION__ >= 202311L
+static const char *
+Scan_Exp (const char *string, thunk *thunks, const char *format, boolean *value)
+#else
static const char *
Scan_Exp (const char *string, thunk *thunks, const char *format, long *value)
+#endif
{
+
+ #if __STDC_VERSION__ >= 202311L
+ boolean temp;
+ #else
long temp;
+ #endif
+
+
if (string[0] == '(') {
string = Scan_Exp(++string, thunks, format, value);
@@ -1277,6 +1289,8 @@
string = Scan_Term(string, thunks, format, value);
+
+
if (string[0] == '=') {
string = Scan_Exp(++string, thunks, format, &temp);
*value = *value == temp;
@@ -1285,18 +1299,23 @@
return string;
}
+
static const char *
Handle_Question_Mark (const char *dformat, thunk *thunks, const char *format)
{
- long true;
-
- dformat = Scan_Exp(dformat, thunks, format, &true);
+ #if __STDC_VERSION__ >= 202311L
+ boolean t;
+ #else
+ long t;
+ #endif
+
+ dformat = Scan_Exp(dformat, thunks, format, &t);
if (*dformat != '(')
Fatal_Error("Bad conditional: '(' expected: %s.", dformat);
++dformat;
- if (!true)
+ if (!t)
dformat = Skip_Past_Right_Paren(dformat);
return dformat;
ie apparently C90 is picky about where variable declarations are in the function. thanks to https://stackoverflow.com/questions/13291353/iso-c90-forbids-mixed-declarations-and-code-in-c for helping with that one.
anyway that last patch is probably best unless someone is expecting ABI stability of Scan_Exp for some reason