lua-users home
lua-l archive

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


Dirk Laurie <dirk.laurie@gmail.com> wrote:

> As far as I am concerned, whatever is not deprecated by Kernihan
> and Plauger [1] is good C style.
> 
> [1] https://en.wikipedia.org/wiki/The_Elements_of_Programming_Style

That is a very nice list to adhere to, thanks for sharing!


Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:

> https://www.kernel.org/doc/html/v4.10/process/coding-style.html

Given they advocate for 8 space wide indentation I'd think that they
would want to save themselves some space! I find it funny that some
of their rational was just literally "K&R" and nothing else.

They also like putting the * for pointers on the variable name, which
is what Lua does as well. My previous experience with Obj-C usually
put the * with the type, which makes more sense to me, but I am now
used to putting it with the var name so either way works.

In the kernel coding style document they state the following:
In general, a pointer, or a struct that has elements that can reasonably
be directly accessed should never be a typedef.

A C string isn't a struct so it has no elements, and as it is always
passed as a pointer to an array of characters I thought this typedef
would be appropriate. I do find a number of examples for it in C++
code online... but not a lot of examples in C code, which seems odd. 


Josh Simmons <simmons.44@gmail.com> wrote:

> const char * is an exceedingly common and standard way of passing
> null-terminated string arguments, anybody who has programmed C before
> will be able to recognise it immediately so all that you achieve by
> hiding it behind a typedef is obfuscation because now a reader has to
> investigate what a l_str is to understand the code.

Sure, but isn't that the same for any typedef you don't know the first
time you encounter it? There are typedefs for other long names as well
such as "typdef unsigned int uint" and the like. Although the Linux
kernel people don't like that either.

Lua has "typedef TValue *StkId" which is used to represent the TValue
pointer as an opaque type. Aren't C strings just opaque types as well?
I guess I just saw creating the typedef for 'const char*' in the same
light as the typedef for StkId.

Now I am a bit torn between using this typedef and not using it. ;)

~Paige