Re: EV_API_DECL inside ev.c

2023-08-31 Thread Marc Lehmann
Hi,

first of all, please see the discussion about
compiler warnings in the documentation:

http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#COMPILER_WARNINGS

On Tue, Aug 29, 2023 at 05:07:23PM +0200, Christian Wendt he/him 
 wrote:
> libev-4.33/ev.c:2143:31: warning: ‘ev_default_loop_ptr’ initialized and
> declared ‘extern’

The warning succinctly describes this line of correct code. The question
that it doesn't answer is: why does it warn about it a line of code that
pretty much can be found verbatim in the C standard document as an example
of correct code? It looks to me to be more of a stylistic warning.

> I don't see that EV_API_DECL is necessary in ev.c.

Thats because you have perfect knowledge of the contents of that macro. If
we hardcoded the values of all macros, indeed many things would be
possible, but they are macros so they can be changed, also in ways we did
not fully predict in advance.

> Without EV_API_DECL, the warning would not be issued.

Right, but other warnings can and will be emitted by other compilers for
the changed line. You can't win, other than by writing correct code and
exercising reason.

(And in fact, if I remember correctly this was introduced specifically to
make it compile with clang).

> If this is about hiding all API in case of EV_API_STATIC, then maybe there
> should be an EV_API_HIDE declared like this:

There are a multitude of other options that complicate code and
maintenance of the library. Given that its impossible to anticipate every
compiler warning of every compiler, we opted for clear and simple code in
this case, rather than hacks to avoid a spurious compiler warning that
warns about perfectly correct code.

-- 
The choice of a   Deliantra, the free code+content MORPG
  -==- _GNU_  http://www.deliantra.net
  ==-- _   generation
  ---==---(_)__  __   __  Marc Lehmann
  --==---/ / _ \/ // /\ \/ /  schm...@schmorp.de
  -=/_/_//_/\_,_/ /_/\_\

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev


EV_API_DECL inside ev.c

2023-08-29 Thread Christian Wendt he/him

Hi,

I get the following warning when compiling libev:

libev-4.33/ev.c:2143:31: warning: ‘ev_default_loop_ptr’ initialized and 
declared ‘extern’
 2143 |   EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs 
to be initialised to make it a definition despite extern */

  |   ^~~

I don't see that EV_API_DECL is necessary in ev.c. Without EV_API_DECL, 
the warning would not be issued.


If this is about hiding all API in case of EV_API_STATIC, then maybe 
there should be an EV_API_HIDE declared like this:


#if EV_API_STATIC
#define EV_API_HIDE static
#else
#define EV_API_HIDE
#endif

This could be used inside ev.c to hide the ev_default_loop_ptr.

Best regards,
Christian Wendt

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/mailman/listinfo/libev