473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to define weak alias in user_defined library

I want to write a library that has a defined function
(special_subroutine in
this example) aliased different names (special_subroutine_1 and
special_subroutine_2 in this example). i.e., I need to call a function
with
different names. Can someone give some help?

I try the following way, but it did not work. Can someone give me a
suggestion?
#gcc -c mylibrary.c
#gcc -c test.c
#gcc -o test test.o mylibrary.o

-------------------------------------------------------
//file name: test.c
//date: 07/09/2006
#include "mylibrary.h"
int main(int argc, char** argv){
...
special_subroutine_1( );
....
special_subroutine_2( );

}
------------------------------------------------------
//file name: mylibrary.c
//date: 07/09/2006
void special_subroutine(void){
....//some computation

}
#ifdef weak_alias
weak_alias(special_subroutine_1, special_subroutine)
weak_alias(special_subroutine_1, special_subroutine)
#endif
--------------------------------------------------

I think MPI library does something like this. e.g it has something like
weak_alias MPI_SEND with PMPI_SEND. Maybe pthread library also does
something similiar.

Jul 12 '06 #1
1 7384
On Wed, 12 Jul 2006, se*********@hotmail.com wrote:
I want to write a library that has a defined function
(special_subroutine in
this example) aliased different names (special_subroutine_1 and
special_subroutine_2 in this example). i.e., I need to call a function
with
different names. Can someone give some help?

I try the following way, but it did not work. Can someone give me a
suggestion?
#gcc -c mylibrary.c
#gcc -c test.c
#gcc -o test test.o mylibrary.o

-------------------------------------------------------
//file name: test.c
//date: 07/09/2006
#include "mylibrary.h"
int main(int argc, char** argv){
...
special_subroutine_1( );
....
special_subroutine_2( );

}
------------------------------------------------------
//file name: mylibrary.c
//date: 07/09/2006
void special_subroutine(void){
....//some computation

}
#ifdef weak_alias
weak_alias(special_subroutine_1, special_subroutine)
weak_alias(special_subroutine_1, special_subroutine)
#endif
You can use #defines, function pointers, or gcc extensions:

(1) Using #defines:
/*
* mylibrary.h
*
* It is the user's responsibility to modify this file
* when ``strong'' definitions become available.
*/
#define special_subroutine_1 special_subroutine
#define special_subroutine_2 special_subroutine

(2) Using function pointers:
/* mylibrary.h */
extern void (*special_subroutine_1)(void);
extern void (*special_subroutine_2)(void);

/*
* mylibrary.c
*
* It is the user's responsibility to reassign the
* pointers when ``strong'' definitions become
* available.
*/
void (*special_subroutine_1)(void) = special_subroutine;
void (*special_subroutine_2)(void) = special_subroutine;

(3) Using gcc extensions (off-topic on comp.lang.c):
#pragma weak special_subroutine_1 = special_subroutine
#pragma weak special_subroutine_2 = special_subroutine

Tak-Shing
Jul 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

94
by: Gabriel Zachmann | last post by:
Is it correct to say that strong/weak typing does not make a difference if one does not use any pointers (or adress-taking operator)? More concretely, I am thinking particularly of Python vs C++....
5
by: Santiago Ordax Solivellas | last post by:
Hi. We have almost all our tables defined on library lib1 and some on lib2. We have alias defined on lib1 to access tables on lib2 so there is no need to qualify library name. Alias for tables on...
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
7
by: Lance | last post by:
Is there any way to create an import alias that applies to the entire project? For example, lets say that I want "VB" to represent Microsoft.VisualBasic throughout my entire project. Is there...
9
by: Neelesh Bodas | last post by:
Hi all, does C++ give a way to declare a specific symbol as a "weak symbol"? In 'C', one can use #pragma directive. Is this still a legal way in C++ ? Is there a (better?) alternative?
5
by: Jon Shemitz | last post by:
I'm playing with 2.0's extern alias declarations and the :: operator. If I have an extern alias My; and the My namespace contains a TypeName, I can refer to My::TypeName .... or to...
13
by: fdmfdmfdm | last post by:
Look at these two codes: =================================== #define int_ptr int* int_ptr a, b; =================================== and ===================================
1
by: channagoud | last post by:
Can any one tell me what a weak alias is ? What is the use of making a weak alias?
4
by: axr0284 | last post by:
Hi, I am currently looking at some code and I am having difficulties figuring out what this peace does: #define FLT_INIT(iEnumValue,boolActive,iWord,iBitMask,iTDS,strDesc) iEnumValue, typedef...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.