From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!goblin2!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Sun, 6 Feb 2011 19:05:58 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <31c357bd-c8dc-4583-a454-86d9c579e5f4@m13g2000yqb.googlegroups.com> <05a3673e-fb97-449c-94ed-1139eb085c32@x1g2000yqb.googlegroups.com> <8r86vgFc3uU1@mid.individual.net> Injection-Date: Sun, 6 Feb 2011 19:05:58 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="4pjzwDT2MPp9AkNxUo/C4Q"; logging-data="31159"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Y2tzekuBLVB0XS4JU58XJf9qZeMPngQ8=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:7AQVO+Su7rS7HLt3seogO4EnIkA= Xref: g2news2.google.com comp.lang.ada:17870 Date: 2011-02-06T19:05:58+00:00 List-Id: On 2011-02-06, Niklas Holsti wrote: > Simon Clubley wrote: >> On 2011-02-04, Ludovic Brenta wrote: >>> Ludovic Brenta wrote: >>>> Syntax Issues wrote on comp.lang.ada: >>>>> ... >>>>> unsigned int print(char *message, unsigned int line) >>>>> { >>>>> char *vidmem = (char *) 0xb8000; >>>>> unsigned int i= 0; >>>>> >>>>> i=(line*80*2); >>>>> >>>>> while(*message!=0) // 24h >>> Did I mention that *every* time I look at C code I see a bug? >>> Sometimes, looking twice at the same code reveals two bugs! Here you >>> do not check that message != NULL; the condition should be: >>> >>> while (message && *message != 0) >>> >> >> That still isn't good enough unless you can guarantee that the compiler >> generated code will not evaluate the second condition if the first condition >> is false. > > That is guaranteed in C. The C "&&" operator is short-circuiting and > corresponds to the Ada "and then". The C99 standard says "If the first > operand compares equal to 0, the second operand is not evaluated." > That's good to know. However, I've used C compilers in the past when it wasn't true so I developed a style of testing the not null condition first in a if statement before going into the while condition. I suspect I am not the first person whose current coding style reflects lessons learnt from using older compilers while those problems have subsequently been fixed in later standards. :-) Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world