0

In function main() {...}

1) #include header file string.h

2) I prototype my own file, call it strcpy:

**char *strcpy(char *strSource , const char *dest);**

3) I also wish to use the "real" strlen function in string.h in main().

4) In another compilation file I have my version of strcpy.

Question: How can I get the linker to choose my version of strcpy instead of the prototype in string.h?

enter code here
#include <conio.h>
#include <string.h>
char *strcpy(char *source , const char *dest); 
void main()
{
char *s, *d;
strcpy(s,d);
getch();
}

#include <stdio.h>
char *strcpy(char *strDestination, const char *strSource)
{
char *ptr;
printf("made it!");
return ptr;
}

2 Answers2

4

You can't do that in C. That's one of the reasons why C++ introduces namespaces.

The only thing you can do is use a non-conflicting name for your own functions.

user703016
  • 37,307
  • 8
  • 87
  • 112
1

This is not a standard thing to do, and I'm pretty sure that if you can do it at all, you will have to read the manual for your linker. And if you try to port this, you will need to read the manual for each linker for each platform to which you try to port this.

The more usual way to do things is to write your own functions with your own names. If you need to hook functionality in a standard library, you would get the source for that library and build your own version.

steveha
  • 74,789
  • 21
  • 92
  • 117