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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:22:19+00:00 2026-05-11T12:22:19+00:00

Greetings Everyone. I’m currently writing a multi-language programe in C, C++ and fortran on

  • 0

Greetings Everyone.

I’m currently writing a multi-language programe in C, C++ and fortran on UNIX, unfortunatly I run into ‘Segmentation Error’ when I try and execute after compiling.

I’ve narrowed down the problem to the interface between the C++ and C sections of my program. The first section consists of main.ccp and SA.cpp, and the second CFE.c.

A class called ‘SimAnneal’ exsists in SA.cpp, with public vectors DensityArray and ElementArray. The order of the program follows:

  1. Create SimAnneal Object ‘Obj1’ and call function ObjFunction()

  2. That function initializes the vector sizes

  3. Call CFE(…) with pointers to both vectors and their length.

  4. CFE.c edits the data elements of the vectors directly via use of the pointers

  5. ObjFunction() uses EnergyArray (and possible DensityArray) data.

The relevant script is below for all sources:

main.cpp

#include 'SA.h'   int main()  {        SimAnneal Obj1;      Obj1.ObjFunction();      return 0; } 

SA.h

class SimAnneal  {     void Initialize ();     ...   public     std::vector<float> DensityArray;      std::vector<float> EnergyArray;     double ObjFunction ();     ... } 

SA.cpp

#include 'CFE.h'  void SimAnneal::Initialize () {     int length = 15;     EnergyArray.resize(length); DensityArray.resize(length); }  double SimAnneal::ObjFunction ()  {     Initialize ();      CFE(&DensityArray[0], &EnergyArray[0], DensityArray.size());         // sends pointers of both arrays to CFE.c, which will then        // directly modify the array      double SumStrainEnergy = 0;      for (int i = 0; i < EnergyArray.size(); i++)     {         SumStrainEnergy += EnergyArray[i];  //Effectively sum of array                                              //engy[] from CFE.c     }      return SumStrainEnergy; } 

CFE.h

#ifdef __cplusplus extern 'C' { #endif   void CFE(float density[], float energy[], int NumElem);  #ifdef __cplusplus  } #endif 

CFE.c

void CFE(float density[], float energy[], int NumElem) {     ...      float * dens;     dens = density;  //pass pointer of array density[0] in SA.cpp to CFE.c      for(n=0; n<NumElem; n++)     { ... modify dens (e.g. DensityArray from SA.cpp) ... }      float * engy;     engy = energy; //pass pointer of array energy[0] in SA.cpp to CFE.c      for(n=0; n<NumElem; n++)     { ... modify engy (e.g. EnergyArray from SA.cpp) ... }    } 

Am I causing an illegal memory access by trying to access the vector elements from the C portion of my program? Is there any sure way to allow this?

Any help would be much appriciated.

  • 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. 2026-05-11T12:22:20+00:00Added an answer on May 11, 2026 at 12:22 pm

    Provided you stay within the bounds of the vector, what you are doing would seem to be OK.

    You can treat a std::vector exactly as if it were a C array by doing what you are doing – taking the address of the first element. The C++ Standard has been changed to specifically allow this kind of usage.

    Can’t find a copy of C++ the Technical Corrigendum 2003 at present, but apparently the relevant section ref is 23.2.4,

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Is the report DLL thread safe? I'm going to guess… May 11, 2026 at 1:57 pm
  • added an answer You need to call BeginReceive on the Socket returned by… May 11, 2026 at 1:57 pm
  • added an answer SELECT OBJECT_NAME(parent_id) AS [Table], OBJECT_NAME(object_id) AS TriggerName FROM sys.triggers WHERE… May 11, 2026 at 1:57 pm

Related Questions

Greetings, I'm trying to find a way to 'unbind' a socket from a particular
Greetings. I'm looking for a way to parse a number of XML files in
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, I'm trying to find either a free .NET library or a command-line executable
Greetings, I need a way (either via C# or in a .bat file) to
Greetings everyone. I'm in need of some experiance here as how to deal with
Greetings Everyone. I'm currently trying to compile a multiple-language program (C, C++ and FORTRAN)
Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on
Greetings everyone, going to need some help in clearing this exception. I get the
Greetings everyone. Having an issue compiling my script containing the following function. Three errors

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.