* [PATCH] sim: fix a warning in dv-sockser.c at connected_p()
@ 2024-05-02 13:23 Bernd Edlinger
2024-05-02 16:15 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Bernd Edlinger @ 2024-05-02 13:23 UTC (permalink / raw)
To: gdb-patches
In some O/S e.g. windows there is a warning here about the
unused variable flags which triggers a -Werror build failure.
Fix that by making the variable declaration optional.
---
sim/common/dv-sockser.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c
index db81233e25b..0cb46947885 100644
--- a/sim/common/dv-sockser.c
+++ b/sim/common/dv-sockser.c
@@ -218,11 +218,14 @@ sim_install_dv_sockser (SIM_DESC sd)
static int
connected_p (SIM_DESC sd)
{
- int numfds,flags;
+ int numfds;
struct timeval tv;
fd_set readfds;
struct sockaddr sockaddr;
socklen_t addrlen;
+#if defined(F_GETFL) && defined(O_NONBLOCK)
+ int flags;
+#endif
if (sockser_listen_fd == -1)
return 0;
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sim: fix a warning in dv-sockser.c at connected_p()
2024-05-02 13:23 [PATCH] sim: fix a warning in dv-sockser.c at connected_p() Bernd Edlinger
@ 2024-05-02 16:15 ` Tom Tromey
2024-05-03 9:00 ` Bernd Edlinger
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2024-05-02 16:15 UTC (permalink / raw)
To: Bernd Edlinger; +Cc: gdb-patches
>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
Bernd> In some O/S e.g. windows there is a warning here about the
Bernd> unused variable flags which triggers a -Werror build failure.
Bernd> Fix that by making the variable declaration optional.
I think this would be better if this declaration were just removed and
then stuck into the condition, like:
/* Set non-blocking i/o. */
#if defined(F_GETFL) && defined(O_NONBLOCK)
int flags = fcntl (sockser_fd, F_GETFL);
^^^ add this here
What do you think?
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sim: fix a warning in dv-sockser.c at connected_p()
2024-05-02 16:15 ` Tom Tromey
@ 2024-05-03 9:00 ` Bernd Edlinger
2024-05-03 15:35 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Bernd Edlinger @ 2024-05-03 9:00 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 5/2/24 18:15, Tom Tromey wrote:
>>>>>> "Bernd" == Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>
> Bernd> In some O/S e.g. windows there is a warning here about the
> Bernd> unused variable flags which triggers a -Werror build failure.
>
> Bernd> Fix that by making the variable declaration optional.
>
> I think this would be better if this declaration were just removed and
> then stuck into the condition, like:
>
> /* Set non-blocking i/o. */
> #if defined(F_GETFL) && defined(O_NONBLOCK)
> int flags = fcntl (sockser_fd, F_GETFL);
> ^^^ add this here
>
> What do you think?
>
This would not be compliant to C99, and it would be the first use of this
C11 feature in this file. Therefore I did not want to go that way.
I did also consider adding braces { } around this whole block, but
actually I do think that guarding the declaration with one #if is also
acceptable and is looking not too ugly, since the function is not too complex.
Thanks
Bernd.
> Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sim: fix a warning in dv-sockser.c at connected_p()
2024-05-03 9:00 ` Bernd Edlinger
@ 2024-05-03 15:35 ` Tom Tromey
2024-05-03 16:07 ` Pedro Alves
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2024-05-03 15:35 UTC (permalink / raw)
To: Bernd Edlinger; +Cc: Tom Tromey, gdb-patches
Bernd> This would not be compliant to C99, and it would be the first use of this
Bernd> C11 feature in this file. Therefore I did not want to go that way.
Bernd> I did also consider adding braces { } around this whole block, but
Bernd> actually I do think that guarding the declaration with one #if is also
Bernd> acceptable and is looking not too ugly, since the function is not too complex.
According to sim/README-HACKING, the sim requires C11 now.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sim: fix a warning in dv-sockser.c at connected_p()
2024-05-03 15:35 ` Tom Tromey
@ 2024-05-03 16:07 ` Pedro Alves
0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2024-05-03 16:07 UTC (permalink / raw)
To: Tom Tromey, Bernd Edlinger; +Cc: gdb-patches
On 2024-05-03 16:35, Tom Tromey wrote:
> Bernd> This would not be compliant to C99, and it would be the first use of this
> Bernd> C11 feature in this file. Therefore I did not want to go that way.
> Bernd> I did also consider adding braces { } around this whole block, but
> Bernd> actually I do think that guarding the declaration with one #if is also
> Bernd> acceptable and is looking not too ugly, since the function is not too complex.
>
> According to sim/README-HACKING, the sim requires C11 now.
>
And declaring a variable in the middle of the block is a C99 feature, not C11, regardless.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-03 16:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 13:23 [PATCH] sim: fix a warning in dv-sockser.c at connected_p() Bernd Edlinger
2024-05-02 16:15 ` Tom Tromey
2024-05-03 9:00 ` Bernd Edlinger
2024-05-03 15:35 ` Tom Tromey
2024-05-03 16:07 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).