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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,97188312486d4578 X-Google-Attributes: gidfc89c,public X-Google-Thread: 109fba,baaf5f793d03d420 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public From: tim@franck (Tim Hollebeek) Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/05 Message-ID: <4u5hcj$q3a@cnn.Princeton.EDU>#1/1 X-Deja-AN: 172415126 references: <320433CE.6D5A@online.no> <4u1g29$hc0@solutions.solon.com> <01bb826a$b222f400$9bee6fce@timhome2> <4u3tt1$qub@solutions.solon.com> <4u5682$qgs@dawn.mmm.com> organization: Princeton University reply-to: tim@wfn-shop.princeton.edu newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada Date: 1996-08-05T00:00:00+00:00 List-Id: Chris Sonnack (cjsonnack@mmm.com) wrote: : Peter Seebach (seebs@solutions.solon.com) wrote: : >>> A lot of programmers used to habitually use a null pointer as a shortcut : >>> for "" for string functions; you'd see : >>> if (strcmp(s, 0)) : >>> used like : >>> if (strcmp(s, "")) : >>> because it worked on some machines. : >> : >> This completely makes the point. Someone who knows assembly language : >> would *never* make that mistake, because it would be so obviously : >> wrong. : > : > An interesting theory. : Not a theory. I've seen it personally. : Because I know what "" really is under the hood, I know it has nothing in : common with a NULL pointer. And I've seen a co-worker, a fellow professional : who's been doing this for a number of years, make the above mistake. Not : just once, but several times. However I'd submit that knowing the difference between "" and NULL is essential to good _C_ programming, and has no relation to whether they know assembly or not. It's a question of the distinction between zero and pointer-to-zero, which one only needs the 'pointer' concept to understand; one does not need to know the underlying machine language constructs. IMO if someone confuses X and pointer-to-X on a regular basis, they don't know C, so you should teach them C instead of trying to get them to misunderstand a new language. : > comp.sys.amiga.programmer, the assembly people would always talk about : > how the first instruction in their programs was always : > movel #0,0L : > : > A high-level programmer would never do that, because someone who has : > learned only the abstract semantics would not think of a null pointer : > as the address of any real memory. It isn't; it's *guaranteed* that : > no object has a null pointer as its address. : Yep. True. (Although, honestly, 90+% of all implementations define NULL : along the lines of: (void*)0) : But that doesn't really change the point that's being made: : >> You cannot program in assembly and not understand a null : >> pointer v.s. a pointer to a zeroed memory location. : This is also true. The point is "" is a real object in memory, and any : assembly programmer would know that. What the NULL pointer is doesn't : matter here; the point is that "" ain't the NULL address. Any C programmer should know a string literal is a *POINTER TO* a real object in memory. I've seen tons of bad C code based on not understanding this. The famous 'if (x == "foo")' is just one example. Now for my biggest objection to this bogus assembly language argument: a C pointer need not be an address at all. Yet you constantly refer to pointers as 'addresses'. Someone has missed a useful abstraction, methinks. --------------------------------------------------------------------------- Tim Hollebeek | Disclaimer :=> Everything above is a true statement, Electron Psychologist | for sufficiently false values of true. Princeton University | email: tim@wfn-shop.princeton.edu ----------------------| http://wfn-shop.princeton.edu/~tim (NEW! IMPROVED!)