lua-users home
lua-l archive

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


nobody <nobody+lua-list@afra-berlin.de> wrote:

> On 2018-02-05 23:50, Paige DePol wrote:
>> 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.
> 
> That's because in C
> 
>  Foo* bar, baz;
> 
> probably isn't what you want[1], and with
> 
>  Foo *bar, baz;
> 
> it's easier to notice.
> 
> -- nobody
> 
> [1]  bar is a pointer, baz isn't.

Yes, attaching the * to the variable name does make declaration statements
like those much easier to parse... and as such I have moved my *'s from the
type name to the variable. It was easy to adopt and retrain myself to use
this style given that the Lua code base uses it as well.

For my 'const char*' typedef I went with 'l_str' to match the existing style
used by Lua... though I suppose I could also just use 'ccstr' for a pretty
obvious abbreviation for 'constant character string'.

While C strings themselves are not technically opaque data types I do think
it could be argued we treat them as such. We simply pass around pointers to
the various functions that work on strings, and because they are declared
'const' we're also not supposed to modify the contents ourselves directly.

I have done some more googling and if you search for "typedef const char"
as an exact phrase the typedef comes up in code bases from a wide range of
companies, from Apple to Microsoft, and a bunch of open source projects.

I also seem to find it referenced quite frequently on Google Books in a
number of books about programming in C++ for some reason. I guess I don't
see 'hiding' the C strings behind a typedef as a bad thing, so for now I
think I will try using the typedef, though I will change it to 'ccstr'.

~Paige