Solved

Alternative to function pointer?

Posted on 2010-11-09
3
694 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

770 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