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: 10a146,a03ae7f4e53958e1 X-Google-Attributes: gid10a146,public X-Google-Thread: fac41,a03ae7f4e53958e1 X-Google-Attributes: gidfac41,public X-Google-Thread: 1014db,a03ae7f4e53958e1 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,8775b19e3c68a5dc X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,a03ae7f4e53958e1 X-Google-Attributes: gid109fba,public X-Google-Thread: 114809,a03ae7f4e53958e1 X-Google-Attributes: gid114809,public X-Google-Thread: fa0ae,a03ae7f4e53958e1 X-Google-Attributes: gidfa0ae,public X-Google-Thread: 1094ba,a03ae7f4e53958e1 X-Google-Attributes: gid1094ba,public From: bill@cafe.net (Kaz Kylheku) Subject: Re: Which language pays most 17457 -- C++ vs. Java? Date: 1997/12/20 Message-ID: <67gvpa$m3t$1@brie.direct.ca>#1/1 X-Deja-AN: 308890762 References: <199712121931.LAA25389@sirius.infonex.com> <67bjnv$j35$1@brie.direct.ca> <349B0417.D4DB6A30@its.cl> Organization: Internet Direct Reply-To: kaz@cafe.net Newsgroups: comp.lang.fortran,comp.lang.c,comp.lang.c++,comp.lang.eiffel,comp.lang.java.programmer,comp.lang.smalltalk,comp.lang.perl.misc,comp.lang.ada,comp.edu Date: 1997-12-20T00:00:00+00:00 List-Id: In article <349B0417.D4DB6A30@its.cl>, Guillermo Schwarz wrote: >This is a multi-part message in MIME format. >--------------EC36FA96B4325E47CB41380A >Content-Type: text/plain; charset=us-ascii >Content-Transfer-Encoding: 7bit > > > >Kaz Kylheku wrote: > >> In article , Tad McClellan wrote: >> >: what do strcmp, strstr etc do? >> > ^^^^^^ ^^^^^^ >> > >> >Those are not *primitives* (ie. built-in to the language). >> > >> >Those are library calls (ie. add-ons to the language). >> >> Nonsense. They are standard parts of the C language required by the ISO >> standard. > >The standard C library, but not he standard C language.In the same way, other >languages have standard libraries. >Some have huge libraries, as Smalltalk does. The library is part of the language, you buffoon, the same way that basic words like 'air' and 'water' are part of English. In C, the standard library functions have special status. First of all, their names are reserved external symbols. If any C program contains an external definition of an identifier that is an external name reserved by the standard library, the behavior is undefined. Secondly, if you include a standard header, you may not redeclare any symbol in that standard header, not even in a nested scope. >> >You won't find 'strcmp' in a C compiler's grammar. >> >> I use a compiler which will inline functions like strcpy() and abs(). > >It has nothing to do with optimization. The point is that C has no built-in support >for Strings. I'm not talking about optimization. I'm talking about recognition of standard functions as thought they where primitives. The C standard permits an implementation to do that. >Even worse, that optimization can be a bug. >What if I define a class: Doh! You can't define a class in C. >class foo() >{ >public: > char * strcmp( char * a, char * b ) { ... } > void bar() > { > ... > strcmp( a, b ); > ... > } >}; > >I wouldn't expect the compiler to "optimize" my code. The above is C++, not C. It defines strcmp as a member function of class foo. It cannot possibly be mistaken for the strcmp in . It's full name is foo::strcmp. It also has a different type signature. Do you have any clue how compilers work? The name strcmp will be looked up in a symbol table for the current scope. The compiler will recognize that it belongs to the class scope foo:: so that it cannot possibly be the standard function. In C, it's like this: a strictly conforming program may not define its own strcmp() function with external linkage. If you want to write your own strcmp, you would have to give it internal linkage using the static keyword: static int strcmp(...) { ... }. You are then forbidden from including the header in that translation unit. The compiler is then required to recognize that you have defined your own strcmp and no longer treat it as a built-in primitive. It works just fine in GCC, for instance. [ nyc.foods, misc.jobs.* trimmed from header ]