--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECL00009 Date: 08/16/97 From: MATHIEU BOUCHARD Time: 02:46am \/To: PETER HAYWOOD (Read 3 times) Subj: Re: Signs of numbers PH> int s, i; PH> i = -647; /* set i to some value */ PH> s = (i < 0 ? -1 : 1); /* set s to -1 if i<0 or 1 if i>=0 */ PH> You could even define a simple macro to perform the same task as PH> your VB function: by the way this SGN is afaik standard in all versions of BASIC or at least TRS-80 Color Basic, GWBASIC, QuickBASIC, PowerBASIC, and most others. PH> #define Sgn(x) (x < 0 ? -1 : x > 0 ? 1 : 0) i would recommend a non-macro one, that avoids nasty side effects, enforces type-checking, and clears out most nameconflicts: template inline int sgn (Any x) { return x<0 ? -1 : x>0; } matju --- Terminate 4.00/Pro * Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECL00010 Date: 08/16/97 From: MATHIEU BOUCHARD Time: 02:58am \/To: BENJAMIN L MCGEE (Read 3 times) Subj: replies here ->[] BLM> How would you define "ascribing to much responsibility to the BLM> constructor?" Is this to much... BLM> manifest::manifest(){ BLM> filename = new char[FILENAME_MAX]; BLM> while (!select(filename, FILENAME_MAX - 1)); BLM> mstreamp = new ifstream(filename); BLM> } this is okay. i often write bigger constructors. (i know the language well enough to know when copies of objects are created, and i make sure references are used everywhere, and make sure no temporaries are created.) matju --- Terminate 4.00/Pro * Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECM00000 Date: 08/17/97 From: TEEMU FRISK Time: 07:16pm \/To: ALL (Read 3 times) Subj: cannot make 3d Hi everybody! I tried to make little 3d-program with one wireframe cube. I got all the points drawed but result wasn't 3d, far of it. So how can I make simple little 3d-engine and draw/move lines/pixels with it? Is there any 3d-related programming site on the net where I can get more fo? --- BBBS/2 v3.42 ToMmIk-6v * Origin: BCG-Box 4 (2:222/0) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECM00001 Date: 08/18/97 From: KURT KUZBA Time: 06:51am \/To: JOSH JACKSON (Read 3 times) Subj: Mpython JJ> They are the knights that say neep! not nee. #include #include #include class Knights_who_say_NEEK { public: Knights_who_say_NEEK(char*); ~Knights_who_say_NEEK(void); int pass_by(char*); private: char *Neek; }; void Knights_who_say_NEEK::Knights_who_say_NEEK(char *P = "shrubbery") { if(*P) { Neek = new char[strlen(P) + 1]; strcpy(Neek, P); } } void Knights_who_say_NEEK::~Knights_who_say_NEEK(void) { delete []Neek; } int Knights_who_say_NEEK::pass_by(char *S) { int pass = 0; if(!strcmp(S, Neek)) { cout << "You may pass" << endl; pass = 1; } else { char *p = Neek; cout << "You may not pass until you bring us...\n" "... A "; for(; *p; p++) cout << char(toupper(*p)); cout << "!!" << endl; } return pass; } void nicky_nicky_nicky_nicky_nU(Knights_who_say_NEEK &K, char *P) { K.pass_by(""); cout << "( giving them a " << P << ". )" << endl; K.pass_by(P); } int main(void) { char c; Knights_who_say_NEEK *knights = new Knights_who_say_NEEK; Knights_who_say_NEEK *knights2 = new Knights_who_say_NEEK ("cookie"); cout << "\n\n\n\n You have encountered the dreaded" " Knights Who Say Neek!\n You must comply with" " their demands to continue!\n\n" << flush; nicky_nicky_nicky_nicky_nU(*knights, "shrubbery"); delete knights; nicky_nicky_nicky_nicky_nU(*knights2, "cookie"); delete knights2; cout << "Enter any character and ENTER to exit." << endl; cin >> c; return 0; } > ] You're trying to make me paranoid, but I'm on to your tricks --- * Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00000 Date: 08/15/97 From: BALOG PAL Time: 03:09am \/To: BENJAMIN L MCGEE (Read 3 times) Subj: couple of ?'s Hi, Benjamin L Mcgee! On 11 Aug 97 15:38:00 you wrote to All BLM> class manifest { BLM> public: BLM> manifest(); BLM> manifest(const char *filename); BLM> ~manifest(); BLM> BLM> void report_name(); report_name() const; ??? BLM> BLM> private: BLM> char* select(char *filename, int len); probably ... const char *filename .. is better BLM> char *filename; BLM> ifstream *mstreamp; BLM> }; BLM> manifest::manifest(const char* manfile){ BLM> filename = new char[FILENAME_MAX]; BLM> strncpy(filename, manfile, FILENAME_MAX - 1); If the given filename is long enough I think you'll end up with a not 0- terminated string. BLM> mstreamp = new ifstream(filename); BLM> } BLM> How do I handle errors in opening the ifstream? Probably the same way you handle all other errors associated with the stream. You probably must supply some interface to ask or clear its status. BLM> Is it a good idea perhaps, to just allocate space for filename within BLM> the constructor and then handle everything else in a manifest::init() BLM> member? That would seem redundant to me but perhaps overloading BLM> constructors is already redundant. Er, I think moving common code to a single function is not redundant but removes ill redundancy. Overloading ctors is not redundant either but in your case I'd better use a single ctor of form: BLM> manifest(const char *filename = 0); That serves for both of your ctors after you insert an if branch. Paul ... Veni, Vidi, VCR--I came, I saw, I taped --- OS/2 Warp * Origin: The FlintStones' Cave in BedRock (2:371/20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00001 Date: 08/17/97 From: BALOG PAL Time: 06:57am \/To: JAVIER KOHEN (Read 3 times) Subj: C++ or ASM? Hi, Javier Kohen! On 11 Aug 97 21:55:40 you wrote to Cameron Clark JK> Actually I'm just casting from (void *) to (virtual char *), see how JK> confusing it is!? What the heck is a (virtual char *) ? JK> const_cast<> can change const but volatile, too. JK> static_cast<> can change anything (mmm... not very sure about it :-), No. You can't cast to a less cv qualified type. So you can't cast away constness unintentionally using this. That is one of this operator's main purpose. Paul ... (C)ontrol (A)lt (B)ye --- OS/2 Warp * Origin: The FlintStones' Cave in BedRock (2:371/20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00002 Date: 08/17/97 From: BALOG PAL Time: 07:05am \/To: BENJAMIN L MCGEE (Read 3 times) Subj: replies here ->[] Hi, Benjamin L Mcgee! On 13 Aug 97 23:14:00 you wrote to All BLM> How would you define "ascribing to much responsibility to the BLM> constructor?" Is this to much... BLM> BLM> manifest::manifest(){ BLM> filename = new char[FILENAME_MAX]; BLM> while (!select(filename, FILENAME_MAX - 1)); BLM> mstreamp = new ifstream(filename); BLM> } Depends on what you want of it. I see no good reason to create an ifstream on the fly. You can simply have a member of type ifstream in your class, that will save a heap operation (and another in dtor). filename is also questionable is you use a platform tith nonlimited stack. Is select is a user-interfaced function, it really can be misplaced in the ctor. There can be situations where you want to instantiate the class but not immediately use it. Then you better leave the filename not selectes right in the ctor, but in a separate member function. But these all depensd on the purpose of the class. Paul ... Beware of programmers who carry screwdrivers --- OS/2 Warp * Origin: The FlintStones' Cave in BedRock (2:371/20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00003 Date: 08/17/97 From: BALOG PAL Time: 07:16am \/To: DANIEL JONES (Read 3 times) Subj: Sunir ventures into C++ Hi, Daniel Jones! On 13 Aug 97 07:06:00 you wrote to Aare Tali AT> for (i = 0; i < 5; i++) AT> do_something(i); AT> for (int j = 0; j < 5; j++) AT> do_something_else(j); AT> if (i < 5) AT> not_everything_was_done_with_i(); AT> if (j < 5) DJ> Did you test this? If so, with what compiler? Probably yes, and using an erlyer compiler DJ> With BC++ 5.01, I get an error: DJ> Undefined symbol 'j' DJ> Why? Because the for() loop defines a block. j is local to that DJ> block, and is out of scope in your "if(j < 5)" statement. As I recall, DJ> this was a matter of some debate, and wasn't implemented in early DJ> versions of C++. I'm reasonably certain that BC++ 3.1 allowed the DJ> above code. Yes, the scoping rule of variables defined in for() changed in the latest C++ draft, so the above code will get an error in the compilers based on the draft. Previously C++ handled the for (int i= ...) like C: it broke the for statement to A; while(b) { ... the block C; } This way wariables defined at the first part went to the csope of the outer block. The change made them to belong in the scope of the block of for. Paul ... WORN disk: Write Once Read Never disk --- OS/2 Warp * Origin: The FlintStones' Cave in BedRock (2:371/20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00004 Date: 08/17/97 From: BALOG PAL Time: 07:25am \/To: DANIEL JONES (Read 3 times) Subj: Sunir ventures into C++ Hi, Daniel Jones! On 14 Aug 97 07:06:00 you wrote to Jerry Coffin DJ> cin << &Number; DJ> vice DJ> cin << Number; cin >> Number ! Paul ... Happiness is a warm gun --- OS/2 Warp * Origin: The FlintStones' Cave in BedRock (2:371/20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: ECN00005 Date: 08/18/97 From: DARIN MCBRIDE Time: 07:16pm \/To: JERRY COFFIN (Read 3 times) Subj: volatile objects? Jerry, or anyone else for that matter,... I'm trying, mostly for the sake of learning, to write a simple multi-threaded comm class. Most of it seems to work, so far, except the queues. I'd like to have a write queue and read queue. That seems simple - there's a deque in the STL. Except that it doesn't really want to work if I make it volatile. If it is volatile, the compiler complains. If it isn't volatile, it becomes really funny - I write to the serial port fine, but reading doesn't always seem to work... if I don't give it a long enough delay, the "AT" coming back from the modem (which I see in a line monitor) only is discovered if I give it a long enough timeout. I'm sure volatile would help here - if I could figure out what I was doing with it. :-) Leaving it non-volatile and then removing the thread/queue for reading may work. However, I'm suspicious that the write queue may not work in stress situations (i.e., trying to send a file). Any ideas? ... Press now to access the pirate software. --- FastEcho 1.46 * Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)