Hi Group,
is there a mean to undefine a function, in a similar way as you can
undefine macros?
For example, let's say that I need a few declarations from stdio.h but
want to define my own printf:
#include <stdio.h>
#undefine-or-similar printf
#include "printf.h"
int main(void)
{
printf(123);
return (0);
}
Thank you.
--
Pietro Cerutti
PGP Public Key: http://gahr.ch/pgp 6 12376
Pietro Cerutti wrote:
is there a mean to undefine a function, in a similar way as you can
undefine macros?
No.
--
Chris "in denial" Dollin
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
Pietro Cerutti wrote:
Hi Group,
is there a mean to undefine a function, in a similar way as you can
undefine macros?
For example, let's say that I need a few declarations from stdio.h but
want to define my own printf:
#include <stdio.h>
#undefine-or-similar printf
#include "printf.h"
int main(void)
{
printf(123);
return (0);
}
No, once a symbol is declared in a compilation unit, it's definition can
not be changed.
The best you can do is something gross like:
#define puts _puts
#include <stdio.h>
#undef puts
void puts( int n ) {}
int main(void) {
puts( 42 );
}
--
Ian Collins.
Ian Collins wrote:
Pietro Cerutti wrote:
>Hi Group, is there a mean to undefine a function, in a similar way as you can undefine macros?
[snip]
No, once a symbol is declared in a compilation unit, it's definition can
not be changed.
The best you can do is something gross like:
#define puts _puts
#include <stdio.h>
#undef puts
void puts( int n ) {}
int main(void) {
puts( 42 );
}
That achieves what I was looking for. Basically, it replaces the
occurrences of "puts" in stdio.h with "_puts", which isn't a function
name. After that, I'm able to declare and define my own version of puts.
Anyway, why I don't get warnings about puts being defined elsewhere
(libc.so)?
Great, thank you!
--
Pietro Cerutti
PGP Public Key: http://gahr.ch/pgp
Pietro Cerutti wrote:
Ian Collins wrote:
>Pietro Cerutti wrote:
>>Hi Group, is there a mean to undefine a function, in a similar way as you can undefine macros?
[snip]
>No, once a symbol is declared in a compilation unit, it's definition can not be changed.
The best you can do is something gross like:
#define puts _puts #include <stdio.h> #undef puts
void puts( int n ) {}
int main(void) { puts( 42 ); }
That achieves what I was looking for. Basically, it replaces the
occurrences of "puts" in stdio.h with "_puts", which isn't a function
name. After that, I'm able to declare and define my own version of puts.
Anyway, why I don't get warnings about puts being defined elsewhere
(libc.so)?
Well I said it was gross and I should have added dangerous and not
portable as well!
Your system uses some form of week symbol for standard library functions
and your function replaced it.
--
Ian Collins.
Ian Collins wrote:
Pietro Cerutti wrote:
>Ian Collins wrote:
>>Pietro Cerutti wrote: Hi Group, is there a mean to undefine a function, in a similar way as you can undefine macros?
[snip]
>>No, once a symbol is declared in a compilation unit, it's definition can not be changed.
The best you can do is something gross like:
#define puts _puts #include <stdio.h> #undef puts
void puts( int n ) {}
int main(void) { puts( 42 ); }
That achieves what I was looking for. Basically, it replaces the occurrences of "puts" in stdio.h with "_puts", which isn't a function name. After that, I'm able to declare and define my own version of puts.
Anyway, why I don't get warnings about puts being defined elsewhere (libc.so)?
Well I said it was gross and I should have added dangerous and not
portable as well!
Your system uses some form of week symbol for standard library functions
and your function replaced it.
Not understood, sorry.
Could you elaborate it or give further directions, please?
Thank you!
--
Pietro Cerutti
PGP Public Key: http://gahr.ch/pgp
Ian Collins wrote:
>
Pietro Cerutti wrote:
Hi Group,
is there a mean to undefine a function, in a similar way as you can
undefine macros?
For example, let's say that I need a few declarations from stdio.h but
want to define my own printf:
[...]
No, once a symbol is declared in a compilation unit, it's definition can
not be changed.
The best you can do is something gross like:
#define puts _puts
#include <stdio.h>
#undef puts
void puts( int n ) {}
int main(void) {
puts( 42 );
}
Or:
#include <stdio.h>
#undef puts
#define puts MyPuts
...
Besides, doesn't the standard forbid you from replacing standard
library functions? For example, I have seen compilers which can
inline some standard functions, like strcpy(), so even if you
had a function called strcpy(), it wouldn't be called.
BTW, is it legal to #undef something that hasn't been #define'd?
Does the above need a #ifdef around the #undef? (My compiler
doesn't complain about it.)
Hold on... I knew I downloaded n1124.pdf for a reason...
Don't mind me. Just go about your things while I have this
conversation with myself.
6.10.3.5p2
(#undef)
It is ignored if the specified identifier is not currently
defined as a macro name.
So, to answer my own question... Yes, it is perfectly legal to
#undef something which isn't #define'd already.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: hokiegal99 |
last post by:
A few questions about the following code. How would I "wrap" this in a
function, and do I need to?
Also, how can I make the code smart enough to realize that when a file
has 2 or more bad charcters in it, that the code needs to run until all
bad characters are gone? For example, if a file has the name
"<bad*mac\file" the program has to run 3 times to get all three bad
chars out of the file name.
The passes look like this:
|
by: David MacQuigg |
last post by:
I'm not getting any feedback on the most important benefit in my
proposed "Ideas for Python 3" thread - the unification of methods and
functions. Perhaps it was buried among too many other less important
changes, so in this thread I would like to focus on that issue alone.
I have edited the Proposed Syntax example below to take out the
changes unecessary to this discussion. I left in the change of
"instance variable" syntax (...
|
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a managed point-of-view I've noticed that:
1) for each managed and unmanaged C function (not C++ classes) I get a
public managed static method (defined on a 'Global Functions' class) in the
generated assembly with an export name of the form...
|
by: Rafal 'Raf256' Maj |
last post by:
Hi,
is there a commend to undefine all macros #define inside a file?
in example:
#define FOR(x) for (..............)
#define MyMacro1(x,y) ...........
// ... code ...
|
by: Bryan Olson |
last post by:
The current Python standard library provides two cryptographic
hash functions: MD5 and SHA-1 . The authors of MD5 originally
stated:
It is conjectured that it is computationally infeasible to
produce two messages having the same message digest.
That conjecture is false, as demonstrated by Wang, Feng, Lai and
Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short-
cut solution for finding collisions in SHA-1 . Their result
| |
by: Tim ffitch |
last post by:
Hi
I have created a VB dll file that contains common functions I use
across various projects in VB, Access and Excel. Rather than have to
code the functions in each I decided to use the dll route.
The problem being that I can't call these functions from the query
designer in Access. I decided that I would try the route of declaring
the functions from the dll file the same way you would for the Windows
API. Access then complains that...
|
by: Timothy Madden |
last post by:
Hello all.
I program C++ since a lot of time now and I still don't know this simple
thing: what's the problem with local functions so they are not part of
C++ ?
There surely are many people who will find them very helpfull. gcc has
them as a non-standard option, but only when compiling C language code,
so I'm afraid there might be some obscure reason why local functions are
not so easy to be dealt with in C++, which I do not yet know.
|
by: Rocky86 |
last post by:
hi people basically I am having a problem with the followinng code:
$names=sizeof($temp);
$report="total=$names&";
foreach($temp as $list)
$report.="name".$names--."=".$list."&";
echo $report;
|
by: Immortal Nephi |
last post by:
My project grows large when I put too many member functions into one
class. The header file and source code file will have approximately
50,000 lines when one class contains thousand member functions. Is it
normal how C++ Compiler can compile large class without any problem?
Didn't C++ Compiler have rules to limit the number of member
functions?
One big object has complex operations how member variables and member
functions can be...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |