The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to override my profile mobile01 High Level Programming 0 11-30-2006 08:35 AM
date override gerry shacter AIX 1 01-08-2006 10:42 PM
script to override natting ppass Shell Programming and Scripting 9 03-22-2005 02:23 PM
Override Mulo IP Networking 1 03-10-2002 06:56 PM
Override protection..... Makaveli.2003 UNIX for Dummies Questions & Answers 1 01-23-2002 11:37 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-31-2006
Registered User
 

Join Date: Feb 2006
Posts: 35
override the function in C

hi ,

greetings ,

I have one doubt reg the C functions .

I have a program sample.c , in which i have function name scanf , which reads a a variable and prints the variable inside the function .
this scanf is nothing to do with C library function scanf , but i would like to use only user defined c function scanf .

when it is compiling , it is throwing error indicating scanf args not matching becos compile checks for stdio.h header file for syntax of scanf .

To put in a simple statement , i would like to override a system function and make my c program to take function which i wrote which has same name .

It can be a similar concept of function overloading in C .

For example :
in case macros i can overide any macro inside my program just by doing #undef name
#define name "unix"

it works for macros ,

in same line how to override the function?


Many Thanks in advance !

Thanks
Naren
Reply With Quote
Forum Sponsor
  #2  
Old 10-31-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
The error comes from the fact that cpp included stdio.h which automatically brings a function prototype for sscanf into the file the compiler sees.

Suggestions:
1. Park your sscanf() module in a separate source file and place every module that calls your sscanf() in that same separate file. In the same file, declare any other function from stdio.h as extern. If you have only one source file, remove stdio.h from the include list and declare everything as extern. You could also make a LOCAL copy of stdio.h and remove references to sscanf from it, rename it, then
Code:
#include "mystdio.h"
2. Rename your sscanf() as mysscanf()
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0