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

  • SEARCH
  • Home
  • 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 7694323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:17:37+00:00 2026-05-31T21:17:37+00:00

I am converting fortran code to C++ and wanted to find a right option

  • 0

I am converting fortran code to C++ and wanted to find a right option for function-pointer.

The fortran code is: for two different cases, it passes two different kinds of function-pointers to another function. These function pointers have different interfaces. In C++, I need to specify interface of function-pointer and hence it is not straightforward. Can someone suggest, if C++ functor or something else, that would be useful? I wish I could use something like ‘void (function) pointer’ and then ‘cast’, but I really don’t know. Thanks in advance.

EDIT: minimal example in fortran

Fortran

if(option1) then
call myfunc( abc_function_pointer,otherarguments)
else
call myfunc( xyz_function_pointer, otherarguments) 
endif

where, these functions are (in C++)

void (*abc_function_pointer)(int, float) //in c++
void (*xyz_function_pointer)(int, int, int) //in c++
  • 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-05-31T21:17:38+00:00Added an answer on May 31, 2026 at 9:17 pm

    Generally speaking, this is a bad idea. Consider – what is myfunc going to do with this function pointer? What happens if you pass it abc_function_pointer, but it tries to call it with three ints? Or vice versa?

    Without knowing what you’re using this for, it’s hard to suggest what you should do. Typically you would want to factor out the common interface between abc_function_pointer and xyz_function_pointer, so myfunc always calls a function with the same type and interface. You can insert a shim function that converts between the common interface and that of abc_function_pointer or xyz_function_pointer.

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

Sidebar

Related Questions

Converting my current code project to TDD, I've noticed something. class Foo { public
I am converting some Fortran90 code to C#. I have some knowledge of Fortran77
While Converting Decimal to String, I tried two methods. Method 1: string a =
As part of my Final Year Project, I need to convert some FORTRAN code
I am converting some Objective-C++ code into plain Objective-C and I am having some
I am converting VBA code that contains the LIKE operator, as in dim sToken
I'm converting existing code to Spring 3 JDBC. I've put it into a class
I am converting a Fortran program to C#. This has to be done in
I've been given the task of connecting my code (fortran) with py (2.5), and
While converting an old code, I encountered the following problem. Given an HTML string,

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.