Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Warning in LLVM Clang

140 views
Skip to first unread message

Mehdi Amini

unread,
Jan 6, 2020, 9:27:54 AM1/6/20
to
Hi,

I have set the -w flag for Clang compiler , on one project I still get
about 100 warnings ; why ?

How to make this #pragma work correctly , I get warnings that they are
correctly known:

#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wall" // -Weverything

// Some function

#pragma clang diagnostic pop

I get:
-Wunknown-pragmas

--
www.my-c-codes.com/

Farewell.

chad

unread,
Jan 6, 2020, 10:48:01 AM1/6/20
to
Because you're a dumbass?

Ben Bacarisse

unread,
Jan 6, 2020, 10:59:08 AM1/6/20
to
Mehdi Amini <ator...@gmail.com> writes:

> I have set the -w flag for Clang compiler , on one project I still get
> about 100 warnings ; why ?

Something, somewhere, is wrong! A first step would be to cut down the
code until you get just one or two warnings and post that code along with the
command used for the compilation.

> How to make this #pragma work correctly , I get warnings that they are
> correctly known:
>
> #pragma clang diagnostic push
> #pragma clang diagnostic warning "-Wall" // -Weverything
>
> // Some function
>
> #pragma clang diagnostic pop
>
> I get:
> -Wunknown-pragmas

I can't reproduce this. It works as expected in a small test case I
just wrote:

$ cat w.c
int f(int x) {}
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wall"
int g(int x) {}
#pragma clang diagnostic pop
int h(int x) {}
$ clang -Wno-all -c w.c
w.c:4:15: warning: control reaches end of non-void function [-Wreturn-type]
int g(int x) {}
^
1 warning generated.


Post the code the does not work for you along with the version if clang
that you are using.

$ clang --version
clang version 8.0.0-3 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

--
Ben.

Guillaume

unread,
Jan 6, 2020, 11:23:43 AM1/6/20
to
Le 06/01/2020 à 15:27, Mehdi Amini a écrit :
> I have set the -w flag for Clang compiler , on one project I still get
> about 100 warnings ; why ?

Likely because the source code is atrociously non-conforming C.
Which IMO would be the first thing to fix before trying to shut up Clang
about it...

Mehdi Amini

unread,
Jan 7, 2020, 7:02:53 AM1/7/20
to
Sorry this is my first major project using a Makefile. It seems to me
that actually GCC is the compiler not Clang. Now how can I disable all
warnings and just show them for a part of code ?

Part of Makefile:

[...]
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -Wall -Wno-parentheses
[...]

--
www.my-c-codes.com/

Farewell.

Mehdi Amini

unread,
Jan 7, 2020, 7:09:16 AM1/7/20
to
I already posted a past thread about this project. Part of the code is
written for pre C89/C90 standard. As I have no alternative to this
project (called "XBoard") , I may continue working on it. My idea is to
disable warnings for others code and enable it for my own added code. In
future I may try to actually fix all warnings.

--
www.my-c-codes.com/

Farewell.

Kenny McCormack

unread,
Jan 7, 2020, 7:58:28 AM1/7/20
to
In article <qv1s14$pi0$1...@dont-email.me>,
Mehdi Amini <ator...@gmail.com> wrote:
...
>Sorry this is my first major project using a Makefile. It seems to me
>that actually GCC is the compiler not Clang. Now how can I disable all
>warnings and just show them for a part of code ?
>
>Part of Makefile:
>
>[...]
>CC = gcc
>CCDEPMODE = depmode=gcc3
>CFLAGS = -Wall -Wno-parentheses
>[...]

By any chance, are you working on a Mac?

On some systems (notably, the Mac), "gcc" is really "clang".
This is actually convenient, because it means that the large quantity of
existing makefiles that use and/or assume gcc will continue to work.

--
I'll give him credit for one thing: He is (& will be) the most quotable President
ever. Books have been written about (GW) Bushisms, but Dubya's got nothing on Trump.

Tremendously wet - from the standpoint of water.

Ben Bacarisse

unread,
Jan 7, 2020, 9:33:25 AM1/7/20
to
Mehdi Amini <ator...@gmail.com> writes:

> On 1/6/20 7:28 PM, Ben Bacarisse wrote:
<cut>
>> I can't reproduce this.
<cut>
>> Post the code the does not work for you along with the version if clang
>> that you are using.

???

> Sorry this is my first major project using a Makefile. It seems to me
> that actually GCC is the compiler not Clang.

I might be clang none the less because gcc point to clang on a Mac. I'd
know if you'd posted the version! Help us to help you.

> Now how can I disable all
> warnings and just show them for a part of code ?

As far as I know, once you've used -w on the command line (as you once
suggested), you can't turn any warnings back on.

> Part of Makefile:
>
> [...]
> CC = gcc
> CCDEPMODE = depmode=gcc3
> CFLAGS = -Wall -Wno-parentheses
> [...]

You can use -Wno-all and then use a pragma to turn -Wall on for the code
you want. You could also use -Wno-everything and turn on the warnings
you want later on. But it might be better to use the pragmas to turn
the warnings off.

However, this reply may be waste of time. You reported a program with
pragmas that I can't reproduce. Post code and versions, so we can help.

--
Ben.

Mehdi Amini

unread,
Jan 8, 2020, 8:05:28 AM1/8/20
to
On 1/7/20 6:03 PM, Ben Bacarisse wrote:
> Mehdi Amini <ator...@gmail.com> writes:
>
>> On 1/6/20 7:28 PM, Ben Bacarisse wrote:

[...]

>>> Post the code the does not work for you along with the version if clang
>>> that you are using.
>
> ???
>

[...]

About code I have to say that it a an opensource multi file project. I
am having problem with a GTK+ signal. So it is not simple to send here
just a small code that has the same behavior. On compiler versions:

:~$ clang --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

:~$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


--
www.my-c-codes.com/

Farewell.

David Brown

unread,
Jan 8, 2020, 9:11:39 AM1/8/20
to
On 08/01/2020 14:05, Mehdi Amini wrote:
> On 1/7/20 6:03 PM, Ben Bacarisse wrote:
>> Mehdi Amini <ator...@gmail.com> writes:
>>
>>> On 1/6/20 7:28 PM, Ben Bacarisse wrote:
>
> [...]
>
>>>> Post the code the does not work for you along with the version if clang
>>>> that you are using.
>>
>> ???
>>
>
> [...]
>
> About code I have to say that it a an opensource multi file project. I
> am having problem with a GTK+ signal. So it is not simple to send here
> just a small code that has the same behavior.

It does not matter how big the source is. What you have to do is figure
out a minimal, stand-alone, compilable snippet of code that demonstrates
the problem. It does not have to be an extraction from the original
code - usually it is better to write a new test "foo" function that has
the same effect. This process has at least three major benefits:

1. It means other people can help you, because they can see a short bit
of code. No one is going to wade through dozens of long source files on
github (or whatever) to help, but many are happy to read through a dozen
lines of code in a Usenet post.

2. During the process of making such a sample, there is a good chance
that you will figure it out yourself, and learn something in the
process. This happens often.

3. You can paste the code into <https://godbolt.org> and test it out
with different compilers, different versions, different warning settings
and flag options. This can be a big help for you in finding out what is
going on.

Mehdi Amini

unread,
Jan 9, 2020, 7:45:44 AM1/9/20
to
On 1/8/20 5:41 PM, David Brown wrote:
> On 08/01/2020 14:05, Mehdi Amini wrote:
>> On 1/7/20 6:03 PM, Ben Bacarisse wrote:
>>> Mehdi Amini <ator...@gmail.com> writes:
>>>
>>>> On 1/6/20 7:28 PM, Ben Bacarisse wrote:
>>

[...]

OK , here is my try on this link:

https://www.tutorialspoint.com/compile_c_online.php

Code:
// pragma problem
#include <stdlib.h>

#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wall" // -Weverything
int main(void)
{
//exit(1);
return 0;
}
#pragma clang diagnostic pop

Result:
$gcc -o main *.c -Wall -Wno-parentheses
main.c:4:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
#pragma clang diagnostic push

main.c:5:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
#pragma clang diagnostic warning "-Wall" // -Weverything

main.c:11:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
#pragma clang diagnostic pop

$main


--
www.my-c-codes.com/

Farewell.

David Brown

unread,
Jan 9, 2020, 8:34:38 AM1/9/20
to
You are using clang-specific pragmas, then compiling with gcc with the
warning for unknown pragmas enabled. The compiler is giving you the
warning you asked for.

Your choices include:

1. Disable the "unknown pragma" warning (gcc -Wall -Wno-unknown-pragmas).

2. Compile with clang.

3. Change the clang-specific pragmas to gcc-specific equivalents:

#pragma GCC diagnostic warning "-Wall"

(clang might happily accept that too - it accepts a fair number of
gcc-specific extensions.)

4. Use conditional compilation testing compiler type, and give
appropriate pragmas for different compilers.

5. Drop the pragma entirely, and put the flags in the builder (makefile,
cmake, or whatever).


Mehdi Amini

unread,
Jan 9, 2020, 9:19:24 AM1/9/20
to
On 1/9/20 5:04 PM, David Brown wrote:
> On 09/01/2020 13:45, Mehdi Amini wrote:
>> On 1/8/20 5:41 PM, David Brown wrote:
>>> On 08/01/2020 14:05, Mehdi Amini wrote:
>>>> On 1/7/20 6:03 PM, Ben Bacarisse wrote:
>>>>> Mehdi Amini <ator...@gmail.com> writes:
>>>>>
>>>>>> On 1/6/20 7:28 PM, Ben Bacarisse wrote:

[...]

>
> You are using clang-specific pragmas, then compiling with gcc with the
> warning for unknown pragmas enabled. The compiler is giving you the
> warning you asked for.
>
> Your choices include:
>
> 1. Disable the "unknown pragma" warning (gcc -Wall -Wno-unknown-pragmas).
>
> 2. Compile with clang.
>
> 3. Change the clang-specific pragmas to gcc-specific equivalents:
>
> #pragma GCC diagnostic warning "-Wall"
>
> (clang might happily accept that too - it accepts a fair number of
> gcc-specific extensions.)
>
> 4. Use conditional compilation testing compiler type, and give
> appropriate pragmas for different compilers.
>
> 5. Drop the pragma entirely, and put the flags in the builder (makefile,
> cmake, or whatever).
>
>

Can I change the Makefile as I originally intended , that is , is it
safe to change these :

CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -Wall -Wno-parentheses

to

CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS =

Then enable warnings on a specific part of code with what you said ? or
even other warnings like -Wextra ?

#pragma GCC diagnostic warning "-Wall"

--
www.my-c-codes.com/

Farewell.

Jorgen Grahn

unread,
Jan 9, 2020, 2:35:17 PM1/9/20
to
On Thu, 2020-01-09, Mehdi Amini wrote:
> On 1/9/20 5:04 PM, David Brown wrote:
>> On 09/01/2020 13:45, Mehdi Amini wrote:
>>> On 1/8/20 5:41 PM, David Brown wrote:
>>>> On 08/01/2020 14:05, Mehdi Amini wrote:
>>>>> On 1/7/20 6:03 PM, Ben Bacarisse wrote:
>>>>>> Mehdi Amini <ator...@gmail.com> writes:
>>>>>>
>>>>>>> On 1/6/20 7:28 PM, Ben Bacarisse wrote:
>
> [...]
>
>>
>> You are using clang-specific pragmas, then compiling with gcc with the
>> warning for unknown pragmas enabled. The compiler is giving you the
>> warning you asked for.
>>
>> Your choices include:
>>
>> 1. Disable the "unknown pragma" warning (gcc -Wall -Wno-unknown-pragmas).
>>
>> 2. Compile with clang.
>>
>> 3. Change the clang-specific pragmas to gcc-specific equivalents:
>>
>> #pragma GCC diagnostic warning "-Wall"
>>
>> (clang might happily accept that too - it accepts a fair number of
>> gcc-specific extensions.)
>>
>> 4. Use conditional compilation testing compiler type, and give
>> appropriate pragmas for different compilers.
>>
>> 5. Drop the pragma entirely, and put the flags in the builder (makefile,
>> cmake, or whatever).

I think here David just commented on your example, which did not show
your original problem. It just showed you mixing clang pragmas and
the gcc compiler.

> Can I change the Makefile as I originally intended , that is , is it
> safe to change these :
>
> CC = gcc
> CCDEPMODE = depmode=gcc3
> CFLAGS = -Wall -Wno-parentheses
>
> to
>
> CC = gcc
> CCDEPMODE = depmode=gcc3
> CFLAGS =
>
> Then enable warnings on a specific part of code with what you said ? or
> even other warnings like -Wextra ?
>
> #pragma GCC diagnostic warning "-Wall"

I strongly recommend enabling maximum warnings in the Makefile (in
CFLAGS), and if it's really necessary, disabling warnings for certain
files, also in the Makefile:

my_weird_file.o: CFLAGS+=-Wno-parentheses

But I don't understand why you can't just live with the warnings, or
fix the code.

Another Make thing: CC is the standard name for the C compiler and
CFLAGS is the standard name for the C compiler options (together with
CPPFLAGS). But CCDEPMODE has, as far as I can tell, no special
meaning in Make.

Lastly, your CFLAGS should also specify what C dialect you want,
optimization and debugging options. I tend to use:

CFLAGS=-Wall -Wextra -pedantic -std=c99 -g -O2

but then I sometimes have to soften it up for individual files,
e.g. those which expect to find POSIX-specific declarations in
standard headers, or which use language extensions.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

James Kuyper

unread,
Jan 9, 2020, 10:08:52 PM1/9/20
to
On 1/9/20 7:45 AM, Mehdi Amini wrote:
...
> https://www.tutorialspoint.com/compile_c_online.php
>
> Code:
> // pragma problem
> #include <stdlib.h>
>
> #pragma clang diagnostic push
> #pragma clang diagnostic warning "-Wall" // -Weverything
> int main(void)
> {
> //exit(1);
> return 0;
> }
> #pragma clang diagnostic pop
>
> Result:
> $gcc -o main *.c -Wall -Wno-parentheses
> main.c:4:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
> #pragma clang diagnostic push
>
> main.c:5:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
> #pragma clang diagnostic warning "-Wall" // -Weverything
>
> main.c:11:0: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
> #pragma clang diagnostic pop
>
> $main

I've heard that there are platforms where "gcc" is actually an alias for
clang. Do you have any reason to believe that's the case on the system
you're using? It doesn't look like it. Try "gcc --version".


David Brown

unread,
Jan 10, 2020, 4:28:15 AM1/10/20
to
Yes, exactly. There isn't enough information in the original post -
that's why we need a small example. If that doesn't show the original
problem, then a new small example is needed.

>
>> Can I change the Makefile as I originally intended , that is , is it
>> safe to change these :
>>
>> CC = gcc
>> CCDEPMODE = depmode=gcc3
>> CFLAGS = -Wall -Wno-parentheses
>>
>> to
>>
>> CC = gcc
>> CCDEPMODE = depmode=gcc3
>> CFLAGS =
>>
>> Then enable warnings on a specific part of code with what you said ? or
>> even other warnings like -Wextra ?
>>
>> #pragma GCC diagnostic warning "-Wall"
>
> I strongly recommend enabling maximum warnings in the Makefile (in
> CFLAGS), and if it's really necessary, disabling warnings for certain
> files, also in the Makefile:
>
> my_weird_file.o: CFLAGS+=-Wno-parentheses
>
> But I don't understand why you can't just live with the warnings, or
> fix the code.

I'd say "fix the code", rather than living with the warnings. Warnings
are given for a reason - they indicate that the code might have
problems. They are not a guarantee that there is a problem, and in some
cases it is merely stylistic differences, which is why you then want to
disable warnings that conflict with your coding style. But I am a
strong believer that your code is not finished if there are /any/
warnings generated with your build process.

>
> Another Make thing: CC is the standard name for the C compiler and
> CFLAGS is the standard name for the C compiler options (together with
> CPPFLAGS). But CCDEPMODE has, as far as I can tell, no special
> meaning in Make.
>
> Lastly, your CFLAGS should also specify what C dialect you want,
> optimization and debugging options. I tend to use:
>
> CFLAGS=-Wall -Wextra -pedantic -std=c99 -g -O2

Agreed - that is a good habit.

Kenny McCormack

unread,
Jan 10, 2020, 4:52:52 AM1/10/20
to
In article <qv8pro$a4d$1...@dont-email.me>,
James Kuyper <james...@alumni.caltech.edu> wrote:
...
>I've heard that there are platforms where "gcc" is actually an alias for
>clang. Do you have any reason to believe that's the case on the system
>you're using? It doesn't look like it. Try "gcc --version".

I think the "He's on a Mac" theory, originally floated by me, has now been
put to rest. Apparently, he's on Ubuntu. It looks like he just has some
code that was written for Clang, and he now wants to compile it on a Ubuntu
system.

Also, "gcc" is not exactly an "alias" - in the usual sense of "alias",
i.e., a shell (bash or [t]csh) alias - on the Mac. Rather, it is a small
(compiled) driver program that converts GCC style command line args into
their Clang equivalents, then invokes Clang, in a way that makes it seem
seamless (heh heh). The point is that this conversion is necessary, since
Clang is *not* command line compatible with GCC (I.e, it is *not* a drop-in
replacement).

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/InsaneParty

David Brown

unread,
Jan 10, 2020, 5:26:56 AM1/10/20
to
On 10/01/2020 10:52, Kenny McCormack wrote:
> In article <qv8pro$a4d$1...@dont-email.me>,
> James Kuyper <james...@alumni.caltech.edu> wrote:
> ...
>> I've heard that there are platforms where "gcc" is actually an alias for
>> clang. Do you have any reason to believe that's the case on the system
>> you're using? It doesn't look like it. Try "gcc --version".
>
> I think the "He's on a Mac" theory, originally floated by me, has now been
> put to rest. Apparently, he's on Ubuntu. It looks like he just has some
> code that was written for Clang, and he now wants to compile it on a Ubuntu
> system.

Yes, I think that is the case, from his posts.

>
> Also, "gcc" is not exactly an "alias" - in the usual sense of "alias",
> i.e., a shell (bash or [t]csh) alias - on the Mac. Rather, it is a small
> (compiled) driver program that converts GCC style command line args into
> their Clang equivalents, then invokes Clang, in a way that makes it seem
> seamless (heh heh). The point is that this conversion is necessary, since
> Clang is *not* command line compatible with GCC (I.e, it is *not* a drop-in
> replacement).
>

I did not realise that this "converter driver" was necessary. Clang is
not a complete drop-in replacement for gcc, either in respect to the
command-line arguments or the way it handles code (especially for
implementation-dependent stuff and extensions), but it is quite close to
being compatible for a good many uses.

Ben Bacarisse

unread,
Jan 10, 2020, 7:39:27 AM1/10/20
to
David Brown <david...@hesbynett.no> writes:
<cut>
> I'd say "fix the code", rather than living with the warnings.

In this case, I'm not sure that's the right approach. If I recall
correctly the code is old and stable (some X-Windows program or other)
so leaving it well alone might be the safest option.

<cut>
--
Ben.

Jorgen Grahn

unread,
Jan 10, 2020, 7:58:01 AM1/10/20
to
Either the thread is confused or I've been a sloppy reader, or both.

If certain source files are written in an old C dialect, I'd change
CFLAGS (warning options, but primarily -std=FOO) for those files.
Not just enable or disable -Wall.

David Brown

unread,
Jan 10, 2020, 8:09:40 AM1/10/20
to
To be more nuanced, I should say "fix the code if you can reasonably do
so". If you can't - such as when you don't want to change the code
unless it is unavoidable - then compiler flags in the build system would
be the next option. I'd still go for that option before the "live with
the warnings" option, but of course it's possible that you can't change
the build scripts either.

However, this code seems to be involving clang pragmas - that does not
sound like an old X program to me.

Mehdi Amini

unread,
Jan 10, 2020, 8:16:04 AM1/10/20
to
On 1/10/20 4:39 PM, David Brown wrote:
> On 10/01/2020 13:39, Ben Bacarisse wrote:
>> David Brown <david...@hesbynett.no> writes:

[...]

> However, this code seems to be involving clang pragmas - that does not
> sound like an old X program to me.

Well , I thought clang is the compiler since it is default compiler for
my IDE (Code::Blocks). But I remembered that I am building from a custom
Makefile. It seems to me that GCC is the compiler.


--
www.my-c-codes.com/

Farewell.

Mehdi Amini

unread,
Jan 10, 2020, 8:18:23 AM1/10/20
to
On 1/10/20 6:38 AM, James Kuyper wrote:
> On 1/9/20 7:45 AM, Mehdi Amini wrote:

[...]
>
> I've heard that there are platforms where "gcc" is actually an alias for
> clang. Do you have any reason to believe that's the case on the system
> you're using? It doesn't look like it. Try "gcc --version".
>
>

Actually I wrote the clang specific #pragma 's. For one way , I can
change them to GCC specific ones.


--
www.my-c-codes.com/

Farewell.

Ben Bacarisse

unread,
Jan 10, 2020, 8:20:14 AM1/10/20
to
The OP is adding them to get the variable warning behaviour being
discussed. I've seen no evidence they were there before, but there have
been rather few details posted.

--
Ben.

Ben Bacarisse

unread,
Jan 10, 2020, 8:23:50 AM1/10/20
to
Jorgen Grahn <grahn...@snipabacken.se> writes:

> On Fri, 2020-01-10, Ben Bacarisse wrote:
>> David Brown <david...@hesbynett.no> writes:
>> <cut>
>>> I'd say "fix the code", rather than living with the warnings.
>>
>> In this case, I'm not sure that's the right approach. If I recall
>> correctly the code is old and stable (some X-Windows program or other)
>> so leaving it well alone might be the safest option.
>
> Either the thread is confused or I've been a sloppy reader, or both.
>
> If certain source files are written in an old C dialect, I'd change
> CFLAGS (warning options, but primarily -std=FOO) for those files.
> Not just enable or disable -Wall.

That might be a good idea as well, but modern compilers give lots of
warnings for old code, even if the right -std argument is used.

For some as yet unexplained reason (the story is coming out in drips),
the OP is adding new code to old source files and wants good warnings
for the new code.

--
Ben.

Mehdi Amini

unread,
Jan 10, 2020, 8:50:34 AM1/10/20
to
Code is a chess GUI which is open-source here available:

https://www.gnu.org/prep/ftp.html

Select a mirror from the list , choose "xboard" package. For now latest
version is 4.9.1 .

I remember compiling/installing it was not easy job though.

Now some typical warnings from original code:

Code1:
if(gameNr < 0 || appData.tourneyType < 1 || // gauntlet engine can
always stay loaded as first engine

Warns1:
CC backend.o
backend.c: In function ‘ReserveGame’:
backend.c:1538:7: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
if(gameNr < 0 || appData.tourneyType < 1 || // gauntlet engine
can always stay loaded as first engine
^~

Code2:
{ "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
Warns2:
./args.h:791:44: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
{ "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
^
Can I fix such warnings ?

--
www.my-c-codes.com/

Farewell.

Mehdi Amini

unread,
Jan 10, 2020, 8:54:26 AM1/10/20
to
On 1/10/20 5:20 PM, Mehdi Amini wrote:
> On 1/10/20 4:09 PM, Ben Bacarisse wrote:
>> David Brown <david...@hesbynett.no> writes:

[...]

> Code1:
> if(gameNr < 0 || appData.tourneyType < 1 ||  // gauntlet engine can
> always stay loaded as first engine

Complete line is:
if(gameNr < 0 || appData.tourneyType < 1 || // gauntlet engine can
always stay loaded as first engine
appData.tourneyType > 1 && nextGame/round != gameNr/round) // in
multi-gauntlet change only after round

[...]

--
www.my-c-codes.com/

Farewell.

Scott Lurndal

unread,
Jan 10, 2020, 10:29:14 AM1/10/20
to
Since most of that code was written in a 32-bit world, if you're building
it in 64-bit worlds -Wall is probably a good idea to sort out any
pointer casting issues.

Keith Thompson

unread,
Jan 10, 2020, 12:34:57 PM1/10/20
to
It sounds like you're still not certain whether you're using gcc or
clang. James is correct, on some systems the "gcc" command invokes the
clang compiler. I believe MacOS is one such system. (Apple decided
they preferred clang over gcc, but a lot of build scripts assume the C
compiler is named "gcc".)

What OS are you on? What does "gcc --version" print? (That will tell
you whether "gcc" invokes gcc or clang.) When you invoke your Makefile,
does it print the commands as it executes them, and does that tell you
what compiler command it's invoking?

--
Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com
[Note updated email address]
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Ben Bacarisse

unread,
Jan 10, 2020, 6:28:20 PM1/10/20
to
Yes, good point. But I don't think the code is abandoned, it just has
some old parts (that's my guess anyway). In other words, he might be
wise to assume that such issues have been addressed at some point in the
last decade or two.

--
Ben.

Ben Bacarisse

unread,
Jan 10, 2020, 6:53:04 PM1/10/20
to
Mehdi Amini <ator...@gmail.com> writes:

> On 1/10/20 4:09 PM, Ben Bacarisse wrote:
>> David Brown <david...@hesbynett.no> writes:
>> <cut>
>>> I'd say "fix the code", rather than living with the warnings.
>>
>> In this case, I'm not sure that's the right approach. If I recall
>> correctly the code is old and stable (some X-Windows program or other)
>> so leaving it well alone might be the safest option.
>>
>> <cut>
>>
>
> Code is a chess GUI which is open-source here available:
>
> https://www.gnu.org/prep/ftp.html
>
> Select a mirror from the list , choose "xboard" package. For now latest
> version is 4.9.1 .
>
> I remember compiling/installing it was not easy job though.
>
> Now some typical warnings from original code:
>
> Code1:
> if(gameNr < 0 || appData.tourneyType < 1 || // gauntlet engine can always stay loaded as first engine
>
> Warns1:
> CC backend.o
> backend.c: In function ‘ReserveGame’:
> backend.c:1538:7: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
> if(gameNr < 0 || appData.tourneyType < 1 || // gauntlet engine can always stay loaded as first engine
> ^~

This warning is about code the looks like this:

if (C)
S1;
S2;

The warning is asking you to check if it should be

if (C) {
S1;
S2;
}

or

if (C)
S1;
S2;

> Code2:
> { "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
> Warns2:
> ./args.h:791:44: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> { "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
> ^

This one is less interesting. CW_USEDEFAULT is (probably) a constant of
type int and ArgIniType is (probably) a 64-bit pointer type. You can
fix this one by including stdint.h and writing

{ "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType)(intptr_t)CW_USEDEFAULT },

> Can I fix such warnings ?

Sure, but is it worth it? Some might be bugs so you would be helping
out and your patches to the source would be welcome, but others might be
considered as adding noise to the code so you'd be doing it for your own
satisfaction.

--
Ben.

Mehdi Amini

unread,
Jan 11, 2020, 6:12:03 AM1/11/20
to
On 1/10/20 9:04 PM, Keith Thompson wrote:
> Mehdi Amini <ator...@gmail.com> writes:
>> On 1/10/20 6:38 AM, James Kuyper wrote:
>>> On 1/9/20 7:45 AM, Mehdi Amini wrote:

[...]

> What OS are you on? What does "gcc --version" print? (That will tell
> you whether "gcc" invokes gcc or clang.) When you invoke your Makefile,
> does it print the commands as it executes them, and does that tell you
> what compiler command it's invoking?
>

:~$ sudo lsb_release -a
[sudo] password for mehdi:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic

:~$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I just have access to Makefile. I compile using Code::Blocks IDE "custom
makefile" feature. So I do not just use a text editor and terminal to
compile the code.From Makefile:

# Makefile.in generated by automake 1.15 from Makefile.am.
# Makefile. Generated from Makefile.in by configure.

In "configure" beginning:
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for xboard 4.9.1.

--
www.my-c-codes.com/

Farewell.

Jorgen Grahn

unread,
Jan 11, 2020, 9:21:11 AM1/11/20
to
On Thu, 2020-01-09, Jorgen Grahn wrote:
> On Thu, 2020-01-09, Mehdi Amini wrote:
...

>> Can I change the Makefile as I originally intended , that is , is it
>> safe to change these :
>>
>> CC = gcc
>> CCDEPMODE = depmode=gcc3
>> CFLAGS = -Wall -Wno-parentheses
>>
>> to
>>
>> CC = gcc
>> CCDEPMODE = depmode=gcc3
>> CFLAGS =
>>
>> Then enable warnings on a specific part of code with what you said ? or
>> even other warnings like -Wextra ?
>>
>> #pragma GCC diagnostic warning "-Wall"
>
> I strongly recommend enabling maximum warnings in the Makefile (in
> CFLAGS), and if it's really necessary, disabling warnings for certain
> files, also in the Makefile:
>
> my_weird_file.o: CFLAGS+=-Wno-parentheses

It later turned out the OP wasn't using Make but the Autoconf stuff
(which happens to generate a temporary Makefile). So the advice above
is not really applicable. I don't know how to deal with Autoconf,
e.g. if it's possible to tell it to use different compiler options for
different files.
0 new messages