--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00003 Date: 07/14/97 From: CAMERON CLARK Time: 12:32am \/To: BOB STOUT (Read 3 times) Subj: Re: Signs of numbers BS> several fatal flaws: You betcha. BS> 1. It only works on two's-complement machines. The C and C++ language BS> standards have been written to allow implementation on machines using BS> other numeric representations. The implementation of the language on a specific machine should take care of the work for you. BS> 2. Your code only works on char's. Any other integral type (short, int, lo BS> will break it. The pseudo-code was meant only to display how to do it for a specific data type. The rest would take too much explaining - not all C++'s have the same size for int,long int, short and the like. Saying "8000" bit for and integer assumes that an int is 32 bits. This is not the case for all compilers. BC4.5 is an example that limits data types depending upon the target type (dos/win16/win32). BS> 3. Your code is guaranteed not to work on floats or doubles. I don't know the standard encoding that C/C++ uses. I've only studied such encodings on a VAX/VMS machine and don't have the bit diagram memorized. Still, one bit of the float is the sign for the encoding I studied and I'm sure its not much different that what C++ specifies. BS> 4. Even if you restrict your functionality *only* integral type and add BS> support for short's, int's, and long's, it will fail on unsigned types. It would be stupid to want to test the sign of an unsigned variable. BS> 5. Depending on your machine's architecture, it may fail on multibyte BS> integral types depending on the "endianness" of your hardware. Bit your tongue. I've ran the code on little and big endian machines - the compiler will uses the correct interpretation of bit possitions. It is from left to right, most to least significants. I've used the same code on vax,dec,alpha,pc. Knowing before hand the 4 of the machines on the network are big endian and I was running a client server on a little endian machine. BS> What I posted previously may be longer than yours, but it will work BS> correctly on machines using any sort of numeric representation, on *any* BS> built-in type, and with either C++ (with or without templates) or C. For readability, I would have used if testing for each case. Ors and Ands are for speed. --- GEcho 1.00 * Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00004 Date: 07/14/97 From: JERRY COFFIN Time: 09:45am \/To: CAREY BLOODWORTH (Read 3 times) Subj: fork for watcom On (12 Jul 97) Carey Bloodworth wrote to Ken Waugh... [ ... ] CB> But of course, I should point out.... The amiga's a dead platform. CB> Even after the first burial, several companies tried to do a CB> Frankenstein's monster on it and it just ended up getting buried CB> again. It's time to let it rest in piece(s). Interesting though discussions of the Amiga architecture are, they're not particularly related to programming in C++; if they're continue, it should be in netmail or some more suitable echo. Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00005 Date: 07/14/97 From: JERRY COFFIN Time: 09:20am \/To: JAVIER KOHEN (Read 3 times) Subj: Graphics routines On (09 Jul 97) Javier Kohen wrote to Jerry Coffin... [ comment about drawing from bottom up being faster than top-down. ] JK> Well, I was indirectely asking for code to try in my hardware config. JK> Sorry if I wasn't clear. Well, presumably you saved the code I already posted. Simply reverse the direction of the loops and compare to the original version. If you have trouble getting the loops reversed and still working, please post your code/questions here. Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00006 Date: 07/14/97 From: JERRY COFFIN Time: 09:23am \/To: FERNANDO ARIEL GONT (Read 3 times) Subj: QUIERO APRENDER C++ On (09 Jul 97) Fernando Ariel Gont wrote to Javier Kohen... FA> I read your message about the one I posted in Spanish.... FA> I agree with you that people outside Argentina don't know anything FA> about our local BBSs. I think it's safe to say that most of the world knows little about the local BBSes in most parts of the world. FA> But about writing my messages in Spanish, I think that the fact that a FA> lot of people around the world speak English is not a valid reason for FA> me to write my messages in that language, because there are millions FA> that speak Spanish... And writing my messages in Spanish is a way of FA> keeping our culture..... (Why not?) "Why not?"...because the echo rules require that messages be written in English, not Spanish. Fido rules make it relatively simple to start up a new echo if you want, so if you want to send messages in Spanish (or any other language) that's fairly easy to arrange. Getting enough other users in that echo to make it worthwhile to send messages may (or may not) be more difficult... I'd add as an aside that since most programming languages themselves are based on English, most programmers are more or less required to understand a fair amount of English. As such, even though it's a lousy choice as a universal language from other viewpoints, this does tend to make English a fairly pragmatic choice of the "universal language" among programmers. FA> I can't understand the difference between "declare" and "define" a FA> function. (I understand by "defining a function" the writing of the FA> algorithm that the function must execute; and by "declaring", the FA> simple execution of that function..... That's OK? Not exactly. Declaring a function means telling the compiler enough about the function that it can compile a call to that function when it needs to. I.e. this is a function declaration: int function(int param1); This simply tells the compiler that `function' requires on parameter of type int, and that it returns an int. This information allows the compiler to make correct choices of overloaded fucntions, and if necessary do things like converting a char parameter to an int before calling the function. A function definition is the function itself. I.e. it contains the body of the function that instructs the compiler what to actually DO when the function is called. FA> What are the "streams class" (or something like that :-)) ? A set of classes devoted to doing I/O under C++. FA> What does "class" mean?. Does it mean "library"? No. A class is a set of related data and code that manipulates that data, as well as providing a set of operations usable by other code. FA> What is the "<<" operator used for ? Doing 1) left shifts on data of built in types, or 2) whatever it's been overloaded to do on data of user defined types. In the latter case, << is often overloaded to do output to a stream, but that's common practice rather than a requirement. FA> This is a fragment of the book I'm reading, where the writer talks FA> about the "cout" object: "Special characters that can't be printed, FA> are are written with "escape sequences", which are composed of a FA> backslash (\), followed by a special code"..... FA> But.... Aren't the "escape sequences" the ones used with the ANSI FA> driver ? I mean, aren't them the ones that need the ANSI driver FA> installed in memory to be printed ? Escape sequences aren't particularly related to cout at all. Escape sequences are a method of representing an otherwise unprintable character in a character or string constant in C or C++. Character and string constants ARE probably used most often for input and output, but that's not any kind of requirement. As far as an ANSI driver goes, yes, some escape sequences are interpreted by ANSI drivers, but others aren't. Some things that C and C++ consider escape sequences represent things that aren't related to ANSI drivers at all. For instance, \b, \r, \n and \a all represent things that don't need an ANSI driver, and in fact will be more or less ignored by most ANSI drivers. FA> The book talks about someyhing like "C-Code Generators" and about "C++ FA> Native-Code Compilers"..... Do "C-Code Generators" still exist? Sure. FA> In many parts of the book, the writer mentions "AT&T"....What's the FA> relation between "AT&T" and the C (or C++) language? Both C and C++ were originally invented/defined by researchers at Bell Labs, which was at the time part of AT&T. (Bell Labs is now part of Lucent Technologies...) Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00007 Date: 07/14/97 From: JERRY COFFIN Time: 10:00am \/To: BOB STOUT (Read 3 times) Subj: Signs of numbers On (13 Jul 97) Bob Stout wrote to Kurt Kuzba... BS> The bottom line is that a single function... BS> int sgn(double x) BS> { BS> if (x > 0.0) BS> return 1; BS> if (x < 0.0) BS> return -1; BS> else return 0; BS> } BS> ...would work just fine in C, but in C++, either a template BS> implementation or overladed functions would be best. I think in this case a templated function is preferrable to an overloaded function: template int sign(const T &x) { if ( x > 0) return 1; else if ( x < 0) return -1; return 0; } This should work for any type for which comparison to 0 and having a sign makes sense. The only problem that might arise would be things like smart pointers that define comparison to 0 only in terms of equal and not equal, rather than less than/greater than. In particular, I've seen a few that would do things like saying a pointer was both less than AND greater than 0, as long as it wasn't equal to 0. In this case, the "sign" you obtained for that pointer type wouldn't depend on the pointer itself, but on the order in which you did the comparisons. These might handle the comparison by defining a conversion of int to the smart pointer, then compare the two, in which case the comparison might not work very well. Strongly preferrable is for the smart pointer to explicitly define the comparison operators it supports (==(int) and !=(int)) and make the conversion from int to smart pointer explicit, meaning you'd have to use `T(0)' to get 0 converted to a pointer. Unfortunately, there are still quite a few compilers around that don't support the explicit keyword. Later, Jerry. ... The Universe is a figment of its own imagination. --- PPoint 1.90 * Origin: Point Pointedly Pointless (1:128/166.5) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00008 Date: 07/13/97 From: CHRISTOPHER BUTLER Time: 09:12am \/To: ALL (Read 3 times) Subj: Help me! :) Hi All! I'm still having problems with my proggy and getch()... in fact, the DOS box (under W95) crashes out if a just press a key, even when the program is off doing something completely different without reading the keyboard... The message I get in Win95 is: === The program tried to exectute an invalid instruction. Fault location: 046F:09CA Interrupts in service: 1 === I don't know if this means anything to anyone? It could just be my very messy code doing horrible things to the computer.. I'll go and try to clean it up :)... Chris ... Programming languages don't do what you WANT them to do, they do what you ... TELL them to do. --- FMail/Win32 1.22 * Origin: Death Butler BBS, +44-1582-620141, 24 Hours (2:257/135) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00009 Date: 07/12/97 From: KEVIN CAMPBELL Time: 06:27pm \/To: ANTHONY TIBBS (Read 3 times) Subj: Help!!! > KC> Yeah, write your own doorgame library :) > KC> It's not hard, all you have to do is read the file Door.Sys > KC> (or equivalent), then use the FOSSIL driver to communicate > KC> to the user. Most of this is covered in the Fido Technical > KC> standards (esp FTS-0015). They should be available from any > KC> Decent BBS. > Yes, but you also have to write an ANSI interpreter too.. Not really, you can use Ascii if you want, although ansi would be a bonus. Still, it's not that difficult and undertaking. Have Fun - Kev Kevin Campbell Sysop of Deimos BBS E-Mail: Sysop@Deimos.unmanned.co.uk --- FMail/386 1.02 * Origin: Mail shipped from Deimos Spaceport (2:258/8) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00010 Date: 07/12/97 From: KEVIN CAMPBELL Time: 06:27pm \/To: LIONEL MAMANE (Read 3 times) Subj: Good C++ Compiler > Just a question: Why not Watcom for Windows? Why don't you recommend > Watcom for > Windows? Well I;ve had reports that it's a pretty poor Windows compiler, and isn't very well based for it. Still, it will do Windows, yes. Have Fun - Kev Kevin Campbell Sysop of Deimos BBS E-Mail: Sysop@Deimos.unmanned.co.uk --- FMail/386 1.02 * Origin: Mail shipped from Deimos Spaceport (2:258/8) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00011 Date: 07/14/97 From: MIGUEL ANGEL SCAPOLLA Time: 06:05am \/To: KURT J. TISCHER (Read 3 times) Subj: RE: Signs of numbers KT> Does Visual C++ have a similar function? If so, in what header ile KT>is it located and what is the name of the function? If not, would someone KT>please show me a function to determine the sign of a number which would KT>return 1 if positive, 0 if zero, and -1 if negative...? This function is implemented with a ternary operator: int sign = (value > 0) ? 1 : ((value < 0) ? -1 : 0); This is equivalent to: int sign; if (value > 0) sign = 1; else if (value < 0) sign = -1; else sign = 0; Or implement this function via macro definition: #define SIGN(x) (((x) > 0) ? 1 : (((x) < 0) ? -1 : 0)) And use this: int z = SIGN (y); Miguel ======================================================== Miguel Scapolla miguelo@blader.com (email) Coronado City miguelo@canopus.com.ar (email) Argentina 4:901/148.30 (fido) ======================================================== --- MjrFIDO 3.25 --- Squish/386 v1.11 * Origin: ISP CANOPUS (BBS) * Bs.As.- ARGENTINA * +54 1 554-2222 (4:90/90) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: EBJ00012 Date: 07/12/97 From: JAVIER KOHEN Time: 03:01am \/To: FERNANDO ARIEL GONT (Read 3 times) Subj: QUIERO APRENDER C++ On 09-Jul-97, Fernando Ariel Gont wrote to Javier Kohen about QUIERO APRENDER C++. FAG> But about writing my messages in Spanish, I think that the fact that a FAG> lot FAG> of people around the world speak English is not a valid reason for me o FAG> write my messages in that language, because there are millions that FAG> speak Spanish..... Javier, leave moderating to moderators... Fernando, stay tuned for a moderator's advice... In the mean-time, stop writing in Spanish in an INTERNATIONAL ECHO, where the only welcomed language is English. Internet: jkohen@tough.com Javier Kohen/The_Crusher ttp://jkohen.base.org Fidonet: 4:900/748.3 Sk-Network: 200:201/126 Rockernet: 33:300/100.3 PGP keyID: 3423EAA9 ... Redundant book title: "Windows For Dummies". -!- CrusherTag 0.3.0. --- Terminate 4.00/Pro * Origin: The King of The Ring BBS +54-1-OFF-LINE TLD 0 - 7 4:900/748.3)