Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:10:31+00:00 2026-06-03T08:10:31+00:00

I am writing a program where a C++ file calls an extern C function

  • 0

I am writing a program where a C++ file calls an extern “C” function in order to launch several CUDA kernel functions. While debugging the code, I discovered that the target address for one of my pointers changes when I enter the extern function.

Here is the offending code (within my .cpp file):

cout << "knnIndices before launch: " << knnIndices_d << endl;

launch_kernel(numParticles, dptr /*positions_d*/, velocities_d, embedded_d, 
    forces_d, 
  #ifndef USE_ATOMIC_FLOAT
    externalForces_d, 
  #endif
    masses_d, knnIndices_d, dt);

cout << "knnIndices after launch complete: " << knnIndices_d << endl;

and within the .cu file:

extern "C" void launch_kernel(int numParticles, float4* positions, float4* velocities,
    float4* embedded, float4* forces,
#ifndef USE_ATOMIC_FLOAT
    int4* externalForces,
#endif
    float* masses, int* knnIndices, float dt)
{
    std::cout << "knnIndices at launch start: " <<  knnIndices << std::endl;

The output from this is:

knnIndices before launch: 0x200420000
knnIndices at launch start: 0x200321400
knnIndices after launch complete: 0x200420000

I’ve run out of ideas trying to explain this behavior, and I would appreciate some help. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:10:32+00:00Added an answer on June 3, 2026 at 8:10 am

    Seems to me like you defined USE_ATOMIC_FLOAT only in one of the sources. So the real index of the parameter is wrong, try printing the parameters that are before and after (or just check the code) to confirm.

    This is one side of C functions, usually if they are in different object files, the symbol contains only the name of the function, and not the parameters…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that calls a function in main that creates a node
I am writing a program that reads the input from a file and then
I'm writing a program that passes data from a file into an array, but
I'm writing a program that needs to access a file inside of c:\program files\program_name\
I am writing a program that maintains a linked_list in a file. So I
I'm writing a program that creates and edits directories and files in a file
I'm writing a program which will allow to load a specific managed .DLL file
Let's say I am writing installation script for the program which contains executable file
I'm writing a Haskell program which generates an XML file. Apparently it is considered
I am writing a program to function as a testing plugin with a third

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.