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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:28:23+00:00 2026-06-05T15:28:23+00:00

I am working on a C math library, and it is using macros do

  • 0

I am working on a C math library, and it is using macros do to the most of it’s work, I am now facing a problem.

This is what the macro looks like:

the_macro(a, b, c)

and the macro itself does something like:
(a - b > 0) ? error_function : 1

the error_function is used to stop the user at complie time, so if (a - b > 0) is true, then the macro will expand as a function which does not have a definition. So this will cause a linkage error.

Everthing seems good, but today my boss told me we need to do some unit-test, so I wrote a function which wraps the macro:

int my_func(int a, int b, int c)
{
    return the_macro(a, b, c);
}

here comes the problem, the code can’t pass linkage, because if I use a var instead of a constant to call the_macro, these error_functions will be in the .o file, because the int a, int b, int c are all known at runtime, so I can only call the macro function with constants: the_macro(2, 3, 4) is there any way to avoid this? or is there a better solution to do unit-test on this macro?

EDIT:

The code I’m working on is confidential… but I made an example which demonstrates the problem:

#include <stdio.h>

#define the_macro(a, b)\
    (a > b)?error_function():1

// Comment out my_func(), then the program will run normaly
// But if you don't comment it out, the linkage error will come out.
void my_func(int a, int b)
{
    the_macro(a, b);
}

int main()
{
    printf("%d\n", the_macro(1, 10));
    return 0;
}

I’m using gcc-4

  • 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-05T15:28:25+00:00Added an answer on June 5, 2026 at 3:28 pm

    Regardless of where you use the macro, if error_function is not declared, you should get a compiler error. If it is declared but not defined, you have undefined behavior. Whether the arguments to the macro are constants or not changes nothing in this respect. (It may affect what the actual behavior is in the case of undefined behavior.)

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

Sidebar

Related Questions

I'm currently using Microchip's Fixed Point Library, but I think this applies to most
I am working on a math library for my DirectX 3D engine in C#.
I am currently working on a C++ sparse matrix/math/iterative solver library, for a simulation
I have this script I am working on that utilizes the oCanvas JS Library
I am working on a platform, which doesn't have the math library, but I
I'm working on tracking objects based on color and I was using EmguCV library
I'm using the most recent PI-OLEDB library to read data from aggregate views in
When I'm working with math in JS I would like its trig functions to
I'm working with a GIS based math library that wraps lower C/C++ code in
I'm writing unit tests using Boost.Test against some old C math library. One of

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.