[Wylug-help] C++ code
Roger Greenwood
rg at nthong.freeserve.co.uk
Tue, 29 Oct 2002 07:10:36 +0000
Philip Wyett wrote:
> Hi,
>
> No int() function call? That is a valid way to enforce a type cast as
> the method you used. both 'blah = (type)foo;' and 'blah = type(foo);'
> are valid and comes with personal style preference. My preferred is the
> method you employ, as it leaves no room for mis-interpretation.
>
> In the above code is constants like EXIT_SUCCESS, BUFSIZE etc. If these
> are define constants, they are dangerous. In small programs they are
> fine, you can easily track them. However in larger projects, they often
> become the source of bugs and are difficult too debug due too their
> nature. The preprocessor merely replaces the word representation with
> the value, not caring what it is aka the type or any relation too other
> code.
>
> An example is 'pi'. Many do:
>
> #define pi 3.141592653589793
>
> while
>
> const float pi = 3.141592653589793;
>
> is safer because the compiler and debugger are left in no doubt what it
> is and can work with it. In the last project I was brought into. 15% of
> the pre-release bug count was down to #define and some creative define
> macros problems. I always encourage not using them wherever possible and
> opting for the safer option IMHO.
>
> Regards
>
> Philip Wyett
It's such a long time ago since I started this program .. . . but I do
remember using the cast as I did and it being approved by the lecturer!!
I have another problem regarding printing now so If you don't mind I
will post the details later (used to be so easy under DOS :-
fprintf(stdprn," Customer :- ");
and it came out on the printer - stdprn was defined in Borland Turbo 'C'
IDE (DOS) and it worked a treat. In fact the original version of this
program still works under win98/NT/2000 (with a bit of network print
redirection).
RG