Re: [PATCH RFC] IB/core, cma: Nice log-friendly string helpers

Bart Van Assche
2015-05-11T07:50:46Z

On 05/10/15 12:45, Sagi Grimberg wrote:
> On 5/10/2015 1:29 PM, Bart Van Assche wrote:
>> On 05/10/15 12:04, Sagi Grimberg wrote:
>>> +#define IB_EVENT(event) \
>>> + ((event) < ARRAY_SIZE(ib_events) ? \
>>> + ib_events[(event)] : "UNRECOGNIZED_EVENT")
>>> +
>>
>> Since a compiler is allowed to use a signed type to implement an enum,
>> please cast "event" to an unsigned type before comparing it with the
>> array size. Additionally, please consider to define IB_EVENT() as an
>> inline function instead of a preprocessor macro.
>
> I can do that, any specific reason why to use inline over macro here?

Not really ... just a general preference for functions over macros. One
of the advantages we all know is that using a function instead of a
macro gives the compiler a chance to perform type checking on arguments.

Bart.