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 679179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:13:52+00:00 2026-05-14T01:13:52+00:00

Basically, here’s my problem. I’m calling someone else’s FORTRAN functions from my C++ code,

  • 0

Basically, here’s my problem. I’m calling someone else’s FORTRAN functions from my C++ code, and it’s giving me headaches. Some code:

function c_error_message()
character(len = 255) :: c_error_message
errmsg(1:9) = 'ERROR MSG'
return
end

That’s the FORTRAN function. My first question is: Is there anything in there that would cause a segfault?

If not, then second: What does that return? A pointer?
I’m trying to call it with the following C statement:

char *e = c_error_message_();

That causes a segfault.

c_error_message();

That too causes a segfault.

I declared c_error_message_() earlier on with the following code:

extern"C" {
    char* c_error_message_();
}

Would declaring a function with a different return type than the actual return type cause a segfault?

I’m at a loss. Thanks for any replies.

  • 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-14T01:13:53+00:00Added an answer on May 14, 2026 at 1:13 am

    Here is a method that works. When I tried to use the ISO C Binding with a function returning a string, the compiler objected. So if instead you use a subroutine argument:

    subroutine fort_err_message (c_error_message) bind (C, name="fort_err_message")
    
    use iso_c_binding, only: C_CHAR, C_NULL_CHAR
    
    character (len=1, kind=C_CHAR), dimension (255), intent (out) :: c_error_message
    
    character (len=255, kind=C_CHAR) :: string
    integer :: i
    
    string = 'ERROR MSG' // C_NULL_CHAR
    
    do i=1, 255
       c_error_message (i) = string (i:i)
    end do
    
    return
    
    end subroutine fort_err_message
    

    The Fortran is a bit awkward because technically a C-string is an 1D array of characters.

    And example C code to demo that this works:

    #include <stdio.h>
    
    void fort_err_message ( char chars [255] );
    
    int main ( void ) {
    
      char chars [255];
    
      fort_err_message ( chars );
    
      printf ( "%s\n", chars );
    
      return 0;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed some help in trying to optimize this code portion ... Basically here's
Basically I am trying to restart a service from a php web page. Here
Basically I have some code to check a specific directory to see if an
Basically here is my code (Authenticator.jsp): window.location.replace(Login.html); // replace method also takes care of
So basically here's my problem. I'm looking for a solution to allow us to
Basically what we have here Getting the headings from a Word document Public Sub
I'm in the process of porting some code from Linux to Mac OS X.
Basically I'm going to go a bit broad here and ask a few questions
Here is a nice underhand lob pitch to you guys. So basically I've got
I'm basically wondering what is included in each error level, as found here in

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.