Re: calling my custom function same as library function
From: Jack Klein (jackklein_at_spamcop.net)
Date: 02/28/05
- Next message: Walter Roberson: "Re: calling my custom function same as library function"
- Previous message: Walter Roberson: "Re: can I know how to write a html parser in C"
- In reply to: Walter Roberson: "Re: calling my custom function same as library function"
- Next in thread: Walter Roberson: "Re: calling my custom function same as library function"
- Reply: Walter Roberson: "Re: calling my custom function same as library function"
- Reply: Kenny McCormack: "Re: calling my custom function same as library function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 21:51:15 -0600
On 28 Feb 2005 02:48:17 GMT, roberson@ibd.nrc-cnrc.gc.ca (Walter
Roberson) wrote in comp.lang.c:
> In article <1109555739.136783.312850@l41g2000cwc.googlegroups.com>,
> Deniz Bahar <deniz.bahar@gmail.com> wrote:
> :I would like to call one of my functions the exact name as an existing
> :C library function (for example K&R2 exercises asks me to make an atof
> :function). If I don't include the header with the declaration for the
> :C library function (stdlib.h in this case) then define/declare my own
> :function with the same name, am I safe?
>
> Library function names are not 'reserved'.
The C standard disagrees:
"7.1.3 Reserved identifiers
1 Each header declares or defines all identifiers listed in its
associated subclause, and optionally declares or defines identifiers
listed in its associated future library directions subclause and
identifiers which are always reserved either for any use or for use as
file scope identifiers."
...and then, in the itemized list that is also part of paragraph 1:
"All identifiers with external linkage in any of the following
subclauses (including the future library directions) are always
reserved for use as identifiers with external linkage."
...therefore, it is undefined to define your own function with the
same name as any standard library function, unless you use the static
keyword to limit it to internal linkage.
Whether or not this particular instance of undefined behavior "works"
is in the eye of the beholder, since the C standard requireth not.
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
- Next message: Walter Roberson: "Re: calling my custom function same as library function"
- Previous message: Walter Roberson: "Re: can I know how to write a html parser in C"
- In reply to: Walter Roberson: "Re: calling my custom function same as library function"
- Next in thread: Walter Roberson: "Re: calling my custom function same as library function"
- Reply: Walter Roberson: "Re: calling my custom function same as library function"
- Reply: Kenny McCormack: "Re: calling my custom function same as library function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|