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: can I know how to write a html parser in C"
- Previous message: Jack Klein: "Re: Riding JNI[Java Native Interface]: Java to C and back"
- In reply to: Deniz Bahar: "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"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 21:47:30 -0600
On 27 Feb 2005 17:55:39 -0800, "Deniz Bahar" <deniz.bahar@gmail.com>
wrote in comp.lang.c:
> Hi,
>
> 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? It seems to work on my
> compiler, but I wonder if this is portable or even acceptable? thx
According to the C standard, it is neither portable nor acceptable to
use the name of a library function in a context where it has external
linkage.
That means, you can define a function named "atof" if and only if you
define it with the static keyword, which means you can only call it by
name from within the same source file.
Otherwise you generate undefined behavior.
-- 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: can I know how to write a html parser in C"
- Previous message: Jack Klein: "Re: Riding JNI[Java Native Interface]: Java to C and back"
- In reply to: Deniz Bahar: "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"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|