geany/geany — comment on commit efcce8808e92ba56684605790959cb014a11c9c8
File:  line 0
By elextr:

On Sun, Nov 6, 2011 at 6:40 AM, Matthew Brush

wrote:
> You mean like this?
>
> ```c
> const char *foo = "abc";
> if (NZV(++foo))
> printf("%s", foo);
> /* prints "c" instead of expected "bc" */
> ```
>
> ```c
> const char *foo = "ab";
> if (NZV(++foo))
> printf("%s", foo);
> /* doesn't print since it evaluates to false (only sees the \0) */
> ```
>
> ```c
> const char *foo = "a";
> if (NZV(++foo))
> printf("%s", foo);
> /* prints whatever follows foo in memory (undefined) */
> ```

Yes, that sort of thing, any expression with side effects is subject
to problems.

if autofools uses the AC_C_INLINE (Waf I dunno) then the following will work:

inline void setptr(gpointer p, gpointer r){ gpointer t=p; p = r; g_free(t); };

If AC_C_TYPEOF is also used then NVL and NZV can be made safe, with
fallback to current unsafe:

#ifdef HAVE_TYPEOF
#define NZV(a)\
({ typeof (a) _a = (a); \
_a && _a[0]; })
#else
#define NZV(a) ((a) && (a)[0])
#endif

#ifdef HAVE_TYPEOF
#define NVL(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a ? _a : _b; })
#else
#define NVL(X
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/geany/geany/commit/efcce8808e92ba56684605790959cb014a11c9c8#commitcomment-697711
>