Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!topaz!nike!sri-spam!argv From: argv@sri-spam.ARPA (AAAARRRRGGGGv) Newsgroups: net.lang.c Subject: Re: Re: Precedent for use of = Message-ID: <6056@sri-spam.ARPA> Date: Tue, 8-Jul-86 22:03:57 EDT Article-I.D.: sri-spam.6056 Posted: Tue Jul 8 22:03:57 1986 Date-Received: Wed, 9-Jul-86 06:41:08 EDT References: <4824@sun.uucp> <499@cbmvax.cbmvax.cbm.UUCP> Reply-To: argv@sri-spam.UUCP (AAAARRRRGGGGv) Organization: SRI International, Menlo Park Lines: 63 In article <499@cbmvax.cbmvax.cbm.UUCP> daveh@cbmvax.cbm.UUCP (Dave Haynie) writes: >> if (i = 0) { >> /* do something */ >> } >> else { >> /* do something else */ >> } >> >> is legal C and usually /* does something else */ than you expected :-) > >As long as you're writing in C, and you REALLY know the language, the above >construct would be ridiculous. I disagree and I believe you do, too. If you really look for this construct, it is quite common in C, altho good programmers comment that they know what they're doing here... for example, my favorite: main(argc, argv) char **argv; { char *prog_name, *rindex(); if (prog_name = rindex(*argv, '/')) /* find last '/' in argv[0] */ prog_name++; /* set prog_name to string following last '/' */ else prog_name = *argv; /* program was exec-ed from same dir or in PATH */ /* etc... */ } This sort of thing is also quite common when using other string(3) routines or basically anything which returns char * I like that much better than doing the same thing via: prog_name = rindex(*argv, '/'); if (!prog_name) prog_name = *argv; else prog_name++; I don't like this method as well simply because there are more statements than needed and the previous version isn't that cluttered. Since the nature of this discussion is the use (or misuse) of the = operator, I would say that C was designed more robustly simply because you can do the above whereas PASCAL won't let you. C gives you the choice of doing it if you prefer to and to do it the other way if you really want to (or don't know better). >I think that most of the folks that are >unhappy with the way that C handles = and == are frustrated Pascal hackers >who can't quite adjust to the power and terseness of C. Maybe if they'd >spend a few extra hours LEARNING C instead of trying to write Pascal in C, >they'd be much better off. [etc..] I quite agree. When I used to work at my school helping students, I found that the students who complained about C were those who just wanted to take the course to get out of the requirement (elective general ed for most). Other comp sci majors who complained about C (either in favor of PASCAL or not) were merely pedantic and just wanted their peers to respect them. I even found that the comp sci faculty that pushed PASCAL knew little about C. Although all of the faculty (whether they kenw C or not) agreed that PASCAL was the correct language to learn for freshmen (I am undecided about this), most of them agreed that it was too limiting for the upper-division courses which concentrated on more important issues. dan (argv@sri-spam.arpa)