[Wylug-help] C++ code

Philip Wyett philipwyett at dsl.pipex.com
29 Oct 2002 09:04:56 +0000


--
On Tue, 2002-10-29 at 07:10, Roger Greenwood wrote:
> 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
>

Hi,

To manipulate IO to printer under C++, it would be via 'ofstream cprn'
as an stdprn alternative, if my memory serves. :) Something on the lines
of:

char* buffer = new char [64];
ofstream cprn(4, buffer, 64);
cprn << "Hello World Printer at LPT1!" << endl;

Regards

Philip Wyett

--

Key pair can be obtained using the link below.

http://www.philipwyett.dsl.pipex.com/PhilipWyett.asc

--
--
Content-Description: This is a digitally signed message part

[ signature.asc of type application/pgp-signature deleted ]
--