473,441 Members | 1,879 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,441 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 7397
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...

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.