--------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300010 Date: 02/25/98 From: BILL BIRRELL Time: 08:40am \/To: BOB STOUT (Read 2 times) Subj: Memory exchange Hi Bob, In a message from Bob Stout to Tom Torfs on 23 Feb 98 12:15:40 about Memory exchange you said:- > Ah, but that depends on how you place the virtual > parentheses *after* you convert it to its guaranteed > equivalent form using simple, rather than compound, > assignment operators. I am disappointed to report that this disgusting little snippet does actually run on all the compilers I have here. There's no explaining it so I won't try. ------------------------------------------------------- #include int main() { char a = 20, b = 92; printf("\n a = %i\tb = %i", a, b); a^=b^=a^=b;return printf("\n a = %i\tb = %i", a, b); } --------------------------------------------------------- Obfuscation is not deliberate. It's just the way the mail reader read it in. A newline after each semicolon or before the "return" should clarify it a bit. I compiled it for all integral types (obviously changing the types and formats to suit) in the hope that at least one compiler would reject it. No such luck! Floats did fail, and that's no surprise at all, but maybe it shows all is not lost. :-) Bill. --- * Origin: bill@escan.demon.co.uk (2:2504/200) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300011 Date: 02/26/98 From: BOB STOUT Time: 07:26am \/To: BILL BIRRELL (Read 2 times) Subj: Memory exchange On , Bill Birrell (2:2504/200@fidonet) wrote: > I am disappointed to report that this disgusting little snippet does > actually run on all the compilers I have here. There's no explaining it > so I won't try. Bill... Actually, I'm not really surprised. There's lots of stuff that exists in legacy code that's technically undefined, but which compilers take great pains to compile "correctly". Having railed publicly at length about what a bad idea it is to use the construct, I'll now readily admit it's a lot harder to find a compiler on which it doesn't work than one where it does. It's still technically incorrect and bad coding practice. My purpose in this crusade hasn't been to protect folks from something that's likely to blow up in their faces, but rather to engender good habits. It's a lot like the void main() thing, it'll usually work OK, but you still shouldn't do it. --- QM v1.00 * Origin: MicroFirm : Down to the C in chips (1:106/2000.6) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300012 Date: 02/26/98 From: KURT KUZBA Time: 07:43am \/To: DONALD BOWERS (Read 2 times) Subj: 'C' & 'C++' DB> Is there an easy way to compile C code on Microsoft DB> Visual C++ 4.0? I've got a bunch of C code, and MSVC DB> keeps giving me a bunch of bunk about obsolete keywords DB> & stuff. Can't it see it's C code and not C++??? It should only require the .C file extension. What sort of keywords is it telling you are obsolete? > ] Sorry. I left my taglines in my other offline reader....... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300013 Date: 02/26/98 From: KURT KUZBA Time: 07:43am \/To: RICHARD MCCONNELL (Read 2 times) Subj: C++ RM> What I want to know is how the LIB files work, and how you RM> know what ones to use. RM> Also the first thing I need to know is how to Display RM> text on screen.... Next how to have a input... By C3.1 do you mean Borland C++3.1? As far as gettting input and displaying to the screen, you can output text in C by inlcuding . What .LIB files you will include depends on what you are trying to do, and what functions it will require. You just use the preprocessor command for the header file #include for instance, where you want to use printf() and fgets() for text input and output. Once we know what you've got, we can help you along with it. Are you going to be programming for DOS or for Windows? They require different approaches. I've now seen a later message, so I understand better what you want to do. In very basic terms, you create blocks of code, using functions from the libraries or making your own. A very simple example of I/O in C is in a following message. > ] I don't think so Tim... I'll go get the Band-Aids........... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300014 Date: 02/26/98 From: KURT KUZBA Time: 07:43am \/To: RUSS WUERTZ (Read 2 times) Subj: WHAT'S HAPPENING HERE RW> But whey do we get oooosymbols in text editors Because they don't use the line feed character, instead displaying it as a character attribute. It only looks like an o. > ] Within every pearl there lies a tiny grain of truth......... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300015 Date: 02/26/98 From: KURT KUZBA Time: 07:43am \/To: RICHARD MCCONNELL (Read 2 times) Subj: Simple I/O in C RM> And now I need help with the basics of C....... Have a look at this once: /*_|_| BIGSTR.C _|_|_| This program demonstrates the use of ANSI functions to _|_|_| construct and implement a function to return a string from _|_|_| the keyboard. (The non-standard function, getch(), is used.) _|_|_| HOME, END, LEFT, RIGHT, BACKSPACE, INSERT, DELETE, and all _|_|_| the text keys are allowed for use. A prompt is optional. _|_|_| A pointer to the default string is returned. There must be a _|_|_| default string with sufficient space for the return string. _|_|_| Released to PUBLIC DOMAIN by Kurt Kuzba. *(12/24/95)*/ #include #include #include #include char *getstr(char*, char*, int, int); int main(void) { char name[33] = "Unknown", buf[33] = ""; int age = 0; getstr("\nEnter your name: => ", name, 30, 16); getstr("\nEnter your age : => ", buf , 2, 2); age = atoi(buf); printf("\n\nNAME: %s\n AGE: %d\n", name, age); return 0; } char *getstr(char *prompt, char *dfault, int strlimit, int winlimit) { char temp[256] = ""; int len = sprintf(temp, "%s", dfault), key = 0, offset = 0, marker = 0, count, home, INS = 1; printf(prompt); while(key != '\r') { for(count = 0, key = 1; count < winlimit; count++) { if(key) if(0 != (key = temp[offset + count])) putchar(key); else putchar('-' + 50 * INS); else putchar('-' + 50 * INS); } printf("%c\b", '-' + 50 * INS); for(count = marker - offset; count < winlimit; count++) putchar('\b'); home = marker - offset; switch(key = ((key = getch()) == 0) ? -getch() : key) { case -82: INS = !INS; putchar('\a'); break; /* INSERT */ case -75: if(marker) /* LEFT */ if(--marker < offset) offset = marker; break; case -77: if(marker < len) /* RIGHT */ if(++marker - offset > winlimit) offset++; break; case -71: marker = offset = 0; break; /* HOME */ case -79: offset = (len > winlimit) ? len - winlimit : 0; marker = len; break; /* END */ case '\b': if(!marker) printf("\a"); /* BACKSPACE */ else { char *bs = &temp[marker--]; len--; while((*(bs - 1) = *bs) != '\0') bs++; if(marker < offset) offset = marker; } break; case -83: if(marker == len) printf("\a"); /* DELETE */ else { char *bs = &temp[marker]; while('\0' != (*bs = *(bs + 1))) bs++; len--; } break; case '\r': strcpy(dfault, temp); break; /* RETURN */ case 25: /* CTRL/Y */ temp[len = offset = marker = 0] = '\0'; break; case 27: key = '\r'; break; /* ESCAPE */ default : if(key < 32 || key > 127) break; /* TEXT */ if(marker >= strlimit) putchar('\a'); else { if(INS && len < strlimit) for(count = len++; count > marker; count--) temp[count] = temp[count - 1]; temp[marker++] = (char)key; len += (len < strlimit && !INS && marker >= len); temp[len] = '\0'; if((marker - offset) >= winlimit) offset = marker - winlimit; } break; } for(count = home; count > 0; count--) putchar('\b'); } return dfault; } /*_|_| end BIGSTR.C */ > ] Presently orbiting Mars in a Supertramp album............... --- * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300016 Date: 02/23/98 From: JOHN RICHARDSON Time: 09:27am \/To: ASHER DENSMORE-LYNN (Read 2 times) Subj: Bjarne Stroustrup's view on C++ Hi Asher, > Stroustrup: It was only supposed to be a joke, I never thought > people would take the book seriously. Anyone with half a brain > can see that object-oriented programming is > counter-intuitive, illogical and inefficient. Whether the interview is genuine or not this paragraph certainly makes sense. :*) John. --- JetMail 0.99beta23 * Origin: The Dysfunctional Refrigerator (fidonet 2:2502/60) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F3300017 Date: 02/24/98 From: AUKE REITSMA Time: 08:39pm \/To: GEORGE WHITE (Read 2 times) Subj: Atotm Hi George, On 21 Feb 98, 08:26, you wrote to Javier Kohen JK>> "Converts strings formated as asctime output to struct tm." JK>> I'd like commentaries on this one. GW> OK ... JK>> struct tm atotm(const char *str) { GW> As you are returning the struct, I think it really needs to be GW> static. Returning a struct is perfectly valid. Though antique compilers won't handle it. Now if he were returning a _pointer_ to struct ... Greetings from _____ /_|__| Auke Reitsma, Delft, The Netherlands.