[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Wget-dev] wget2 | Documenting 'static inline' functions from wget.h

From: Darshit Shah
Subject: Re: [Wget-dev] wget2 | Documenting 'static inline' functions from wget.h (#396)
Date: Mon, 20 Aug 2018 15:02:14 +0000

Using a macro for an inlined function is an artefact of C90 and ANSI C. When 
writing modern code, we should not remain stuck to these old techniques.

Let me talk about the cons first:

1. I really don't think that we should move to a bad-programming practice 
simply because our documentation engine cannot handle the alternative.

2. C90 and older C standards will refuse to compile with the `inline` keyword. 
To do that, we can use the `__inline__` keyword instead as mentioned 
 The only other options where a compiler will not inline the function are:
  - Based on the low-level decision of the compiler. In this case, the compiler 
is almost always right and we should let it do its job.
  - It is a non-optimizing compiler. In this case, the overall memory footprint 
and speed is already going to be fairly slow and the additional cost of a copy 
of some small functions will not add up to anything consequential. Also, even 
non-optimizing compilers often perform a dead-code pruning in which case, the 
code for such functions will get pruned out.

macro based function calls, especially in a header file is a very bad idea. A 
`#define`'d function has no type checking done at all. Also, the debugger 
support for preprocessor commands is very limited. So, when you have an issue 
and put your program in the debugger, you will not see the exact instructions 
being executed. When someone accidentally passes a negative value for `len`, 
you want the compiler to complain about it, not accept it silently. That is why 
we use inline functions.

Reply to this email directly or view it on GitLab: 
You're receiving this email because of your account on gitlab.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]