Solved

Alternative to function pointer?

Posted on 2010-11-09
3
692 Views
Last Modified: 2012-05-10
Hello,

I need to define a function in one file but reference it in another. I am currently doing this by passing a function pointer. However, I can no longer use function pointers for this*, so is there an alternative way of achieving the same thing?

Thank you!

* For those interested in why: I am actually using C for CUDA, and it turns out that the architecture version one needs to compile for in order to use the 'constant memory' on GPUs does not support function pointers within GPU kernels! And since using constant memory is more important for me than using function pointers, I am forced to look for an alternative.
0
Comment
Question by:InteractiveMind
3 Comments
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 200 total points
ID: 34098375
You have two choices to call a function, you either call it directly or indirectly via a function pointer.
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 300 total points
ID: 34099731
I'm a bit confused : unless the function is static (ie. local to the compilation unit), you can just call it. If it is static, then you probably shouldn't be calling it (assuming there was a good reason to make it static in the first place).

Maybe you can show some code, so we get a better idea of what you're dealing with ?
0
 
LVL 25

Author Closing Comment

by:InteractiveMind
ID: 34277450
Sorry for the delay, I've been very busy lately. I didn't realise I could just call a function in another file without first including it - so thank you!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now