lua-users home
lua-l archive

Re: Modules for iconv (Was: UTF-8 patterns in Lua 5.3)

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


Am 19.04.2014 23:18 schröbte Sean Conner:
It was thus said that the Great Coroutines once stated:
I think what you have there is a compound literal, bro: &(int){1}
 Ah, thanks. I couldn't remember the name of the concept.
Actually a nice concept. Helps with defining type-safe integer typedefs ...
 I also love <stdint.h> and <stdbool.h>. The former replaces a large block
of preprocessor code I used to use to get known sized integers, and the
later gives me booleans, true and false (okay, so booleans are a bit larger
than 1 bit, but hey, I can live with that).
I think we all wish booleans were 1-bit for memory concerns, but
accessing word-sized primitives is much faster -- which is why it's
traditionally defined as an int.
 GCC uses a byte to store a bool. But if C had restricted taking the
address of a bool (which I doubt could be done in practice) then maybe it
could have gone with bit-packing bools.
What about arrays of bools (which implicitly convert to pointer to first element), or passing a pointer to bool so that you can modify it? Not to mention that you probably would save space anyway, because of padding and alignment requirements.
I find myself doing this even if 'bool' does exist because I have to
write code for both WIndows, sometimes Solaris, and the non-fucky
platforms:
typedef int boolean;
#if true
#elseif
# define true 1
#endif
#if false
#elseif
# define false 0
#endif
That would break if someone defined `false` to be 0.
 I tend to define those values as:
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE !FALSE
#endif
 I felt it was a bit safer that way, because in C, true is anything other
than 0.
I assume you know by now that `!FALSE` is exactly the same as `1` ...
The only sane pre-C99 choice is *not* to define TRUE (the nice thing about C99's _Bool is that there are only two values).
 -spc
Philipp

AltStyle によって変換されたページ (->オリジナル) /