Solved

Alternative to function pointer?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-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.

856 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