Skip to content

Conversation

@jschueller
Copy link
Contributor

Rationale: this allows to forward-declare callback data types in case a callback needs to be declared in a public header:

struct _HighsCallbackDataOut;
struct _HighsCallbackDataIn;
typedef _HighsCallbackDataOut HighsCallbackDataOut; typedef _HighsCallbackDataIn HighsCallbackDataIn;

This allows to forward-declare callback data types in case a callback needs to be declared in a public header:

struct _HighsCallbackDataOut;
struct _HighsCallbackDataIn;
typedef _HighsCallbackDataOut HighsCallbackDataOut;
typedef _HighsCallbackDataIn HighsCallbackDataIn;
@jajhall jajhall changed the base branch from master to latest October 30, 2025 20:25
Structs don't have a leading "_" in HiGHS
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.08%. Comparing base (869cbd4) to head (fe506f8).
⚠️ Report is 41 commits behind head on latest.

Additional details and impacted files
@@            Coverage Diff             @@
##           latest    #2625      +/-   ##
==========================================
+ Coverage   81.06%   81.08%   +0.01%     
==========================================
  Files         347      347              
  Lines       85219    85313      +94     
==========================================
+ Hits        69083    69176      +93     
- Misses      16136    16137       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@galabovaa
Copy link
Contributor

@jschueller Would

typedef struct HighsCallbackDataOut {
...

without

typedef _HighsCallbackDataOut HighsCallbackDataOut; 

allow forward-declaring as well? Could you give us an example of the code you need to build, if possible? If you define another HighsCallbackDataOut would that not be an issue?

@jschueller
Copy link
Contributor Author

jschueller commented Oct 31, 2025

no, that wouldnt work (error: conflicting declaration ‘typedef struct HighsCallbackDataOut HighsCallbackDataOut’)

here is what I'm trying to do in a nutshell:

Solver.hxx:

#include <iostream>

// predeclaration (public header, so we cannot use highs.h here)
struct _HighsCallbackDataOut;
struct _HighsCallbackDataIn;
typedef _HighsCallbackDataOut HighsCallbackDataOut;
typedef _HighsCallbackDataIn HighsCallbackDataIn;


class Solver
{
public:
  Solver() {};
  void run() {};

protected:
  // we need to declare this here because we want to access protected member of the Solver class
  static void Callback(const int callback_type,
                       const char* message,
                       const HighsCallbackDataOut* data_out,
                       HighsCallbackDataIn* data_in,
                       void* user_callback_data);
};

Solver.cxx:

#include "Solver.hxx"

// actual include of highs
#include <Highs.h>


void Solver::Callback(const int callback_type,
                       const char* message,
                       const HighsCallbackDataOut* data_out,
                       HighsCallbackDataIn* data_in,
                       void* user_callback_data) {}

@galabovaa
Copy link
Contributor

I tried this minimal example locally, and, with the HiGHS code from latest, simply declaring the struct compiled as well:

Solver.hxx

#include <iostream>

struct HighsCallbackDataOut;
struct HighsCallbackDataIn;

class Solver
{
public:
  Solver() {};
  void run() {};

protected:
  static void Callback(const int callback_type,
                       const char* message,
                       const HighsCallbackDataOut* data_out,
                       HighsCallbackDataIn* data_in,
                       void* user_callback_data);
};

and
Solver.cxx

#include "Solver.hxx"

// actual include of highs
#include <Highs.h>


void Solver::Callback(const int callback_type,
                       const char* message,
                       const HighsCallbackDataOut* data_out,
                       HighsCallbackDataIn* data_in,
                       void* user_callback_data) {}
                       

This way you still include Highs.h only in your implementation file. Do you get a different error?

@jschueller
Copy link
Contributor Author

yes, I still get a conflicting declaration with your solution

I prepared a repo to replicate the issue, see the github actions logs:
https://github.com/jschueller/hello-highs.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants