Deutsch English Français Italiano |
<l522g2FqgibU6@mid.individual.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!uucp.uio.no!fnord.no!news1.firedrake.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: rbowman <bowman@montana.com> Newsgroups: comp.os.linux.advocacy Subject: Re: OT programming challenge: fastest/best/shortest C program to jumble a sentence, then restore it Date: 9 Mar 2024 03:14:10 GMT Lines: 50 Message-ID: <l522g2FqgibU6@mid.individual.net> References: <65e9cad3$0$4689$882e4bbb@reader.netnews.com> <l4ufsbF9kdnU4@mid.individual.net> <usf2m9$1n0jh$2@dont-email.me> <l518d6FmepqU1@mid.individual.net> <usfs1a$1svs6$1@dont-email.me> <usft59$1t70f$1@dont-email.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 5zDGJIoBqZzfjLF2dhyzjA3vA+GU83XVLBb6r5EG5z4j+YoS61 Cancel-Lock: sha1:6ERtMwqGKocd84W/XJNxI3pp5vI= sha256:iid56JqBdV6fCFZDMKlbwENoEyH0kywKhSPlPv0oBW8= User-Agent: Pan/0.149 (Bellevue; 4c157ba) Bytes: 2255 On Fri, 8 Mar 2024 15:41:13 -0500, DFS wrote: > Sorry. That's ALL from a crlf inserted by the newsreader. It compiled > cleanly after I took it out. Yup... In production code I'd likely do char* sentence; sentence = strdup("Once you try it, you'll see it doesn't need spice."); if (sentence == NULL) { printf("strdup() failed: %s", strerror(errno)); return -1; } Admittedly is the implied malloc() failed the odds of it printing anything aren't great but might as well try. I probably would use strtok_r() in production if there was a remote possibility that there would be another nested strtok(). That's ruined more than one programmer's day. It does make one appreciate Python when you're not scrambling for the last nanosecond. I recently came across an article about MicroPython on the Pico by someone who hung a logic analyzer on an output. The first observation was def Blink(): While True: pin.on() pin.off() Blink() was faster than an in-line While True: pin.on() pin.off() The second observation was if you were working with nanoseconds it was time to move to C. No surprise on the second but apparently the generated code is a little better optimized in a function.