473,396 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,396 software developers and data experts.

get the address of a function??

Is the following program print the address of the function?

void hello()
{ printf("hello\n");
}

void main()
{
printf("hello function=%d\n", hello);
}

please advice. thanks....

Nov 1 '06
54 24426
Jordan Abel wrote:
2006-11-05 <wm***************************@JUPITER1.PC-ROSENAU.DE>,
Herbert Rosenau wrote:
On Sat, 4 Nov 2006 22:19:44 UTC, Jordan Abel <ra****@random.yi.org>
wrote:
2006-11-04 <11*********************@h54g2000cwb.googlegroups. com>,
ma*****@gmail.com wrote:
Could dlsym() be considered a valid way of doing this? At least for the
POSIX-compliant compilers/systems?

Not really. on a POSIX system, or really anything that supports dlsym,
conversion between function pointers and void * is defined anyway.
No. void* may even not wide enough to hold an address of a function.

On a POSIX system, it is. It's in that _other_ standard, you know? So
using dlsym (which is the reason why POSIX requires it) trickery for
this purpose is beyond silly. Either it'll work or dlsym() won't.
dlsym() is part of the XSI extension to POSIX, not of POSIX itself. (I
know a lot of people posted that POSIX requires it, so this is not
directed at you in particular.)

Nov 6 '06 #51
2006-11-06 <11**********************@k70g2000cwa.googlegroups .com>,
Harald van D?k wrote:
Jordan Abel wrote:
>2006-11-05 <wm***************************@JUPITER1.PC-ROSENAU.DE>,
Herbert Rosenau wrote:
On Sat, 4 Nov 2006 22:19:44 UTC, Jordan Abel <ra****@random.yi.org>
wrote:

2006-11-04 <11*********************@h54g2000cwb.googlegroups. com>,
ma*****@gmail.com wrote:
Could dlsym() be considered a valid way of doing this? At least for the
POSIX-compliant compilers/systems?

Not really. on a POSIX system, or really anything that supports dlsym,
conversion between function pointers and void * is defined anyway.

No. void* may even not wide enough to hold an address of a function.

On a POSIX system, it is. It's in that _other_ standard, you know? So
using dlsym (which is the reason why POSIX requires it) trickery for
this purpose is beyond silly. Either it'll work or dlsym() won't.

dlsym() is part of the XSI extension to POSIX, not of POSIX itself. (I
know a lot of people posted that POSIX requires it, so this is not
directed at you in particular.)
Well, my point was rather "dlsym is never useful for this, because if
dlsym is available, you can cast it to void* anyway", so it still
stands. (And I seem to recall that POSIX still requires function pointer
to void*, but I could be wrong)
Nov 6 '06 #52
CBFalconer <cb********@yahoo.comwrote:
Simon Biber wrote:
There is no lack of knowledge of the size involved. You can get it from
sizeof. Either sizeof f, or sizeof (int(*)(void)).

I don't think so. A function pointer may be a large involved
thing, such as fields for segment, offset, in/out_ofmemory, etc. I
don't think sizeof can cope with this.
If it didn't, you couldn't have arrays of function pointers.

Richard
Nov 6 '06 #53
Richard Bos wrote:
CBFalconer <cb********@yahoo.comwrote:
>Simon Biber wrote:
>>There is no lack of knowledge of the size involved. You can get it from
sizeof. Either sizeof f, or sizeof (int(*)(void)).
I don't think so. A function pointer may be a large involved
thing, such as fields for segment, offset, in/out_ofmemory, etc. I
don't think sizeof can cope with this.

If it didn't, you couldn't have arrays of function pointers.

Richard
Very good point. Bos is boss. :-)

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 7 '06 #54
Joe Wright <jo********@comcast.netwrote:
Richard Bos wrote:
CBFalconer <cb********@yahoo.comwrote:
Simon Biber wrote:
There is no lack of knowledge of the size involved. You can get it from
sizeof. Either sizeof f, or sizeof (int(*)(void)).
I don't think so. A function pointer may be a large involved
thing, such as fields for segment, offset, in/out_ofmemory, etc. I
don't think sizeof can cope with this.
If it didn't, you couldn't have arrays of function pointers.

Very good point. Bos is boss. :-)
No, Bos is Wood.

Richard
Nov 7 '06 #55

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

Similar topics

11
by: Larry R. Baker | last post by:
What is the best way to pull a pc's Mac Address from a web page? Larry
11
by: John Collyer | last post by:
Hi, In assembly language you can use a lookup table to call functions. 1. Lookup function address in table 2. Call the function Like: CALL FUNCTION
4
by: Marco Snoek | last post by:
Hya, Think it's a simple question: on a page I have a couple of IFRAME's loaded on top of each other, only one visible. With a simple: ...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
2
by: Kurt Ng | last post by:
Hi, y'all. Can anyone help me on this problem? I'm working with a third-party C dll, and I'm having trouble importing into C# the dll's methods that return one of the dll's defined types,...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
6
by: Todd A. Anderson | last post by:
I have a function foo of which I need to get the address. The problem is that when you say "&foo" (or just foo for that matter), you get the address of this function's entry in a jump table and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
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,...
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
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...

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.