[Wylug-help] C++ code

Roger Leigh roger at whinlatter.uklinux.net
29 Oct 2002 22:35:57 +0000


Roger Greenwood <rg@nthong.freeserve.co.uk> writes:

> > I would suggest using libreadline instead of gets/fgets, but you
> > *must* have GPL licensed your code to link with it.
>
> I'm having more success with :-
>
> cin.getline(entry,5);

I thought the example was in C?

> > >From an aesthetic point-of-view, I don't like the TRUE and FALSE
> > macros; just use if (valid) or if (!valid) which are much safer and
> > easier to read (if TRUE is 0, FALSE is !0, not 1 and vice-versa).  The
> > definition of true and false can also change:
>
> Yes they are defined :-
>
> //******************************************************
> // # DEFINES  and global variables
> //******************************************************
> #define TRUE 1
> #define FALSE 0
>
> This code was written some time ago so I'm sorry I got it wrong - I
> think I defined it like that because there was no defined standard that
> I knew about.

There's nothing strictly wrong with it, it's just that the macros
won't always work.  The condition "true" is not 1, it is "not zero",
and what value is true or false (in terms of macros) depends on the
context, e.g. some functions return nonzero on failure, some use zero.
Because of this, I think it's cleaner not to hide the true values
behind macros.

> I have never heard of libreadline.

If you use the bash shell, you use it everyday.  It gives you command
and filename completion, a history buffer and searching, keyboard
shortcuts and dynamic memory allocation so it can't cause buffer
overflow.  It's the canonical input function on GNU systems, and is
used by many shells and interactive programs e.g. psql, the PostgreSQL
interactive SQL client.  It's distributed with bash.



--
Roger Leigh
                "Liberty and Livelihood" - Support the Countryside Alliance
                Need Epson Stylus Utilities? http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848 available on public keyservers