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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:03:05+00:00 2026-05-16T15:03:05+00:00

I was reverse engineering some code and came across this… /************************************************************************/ /* */ /*

  • 0

I was reverse engineering some code and came across this…

/************************************************************************/
/*                                                                      */
/*                          MACRO CHECK_FREAD                           */
/*                                                                      */
/*  CHECK_FREAD is used to check the status of a file read.  It         */
/*   is passed the return code from read and a string to print out if   */
/*   an error is detected.  If an error is found, an error message is   */
/*   printed out and the program terminates.  This was made into a      */
/*   macro because it had to be done over and over and over . . .       */
/*                                                                      */
/************************************************************************/

#define CHECK_FREAD(X, msg)  if (X==-1) \
                 { \
                return(DCD_BADREAD); \
                 }

Basically, the particular set of functions in this file call this whenever they do a (c-read) to check the result for an error. They also have a similar check for EOF… Basically as far as I can tell, they’re doing it this way to insert returns on error in the middle of their function in a bunch of places.

e.g.

/*  Read in an 4                */
    ret_val = read(fd, &input_integer, sizeof(int32));

    CHECK_FREAD(ret_val, "reading an 4");
    CHECK_FEOF(ret_val, "reading an 4");

    if (input_integer != 4)
    {
        return(DCD_BADFORMAT);
    }

    /*  Read in the number of atoms         */
    ret_val = read(fd, &input_integer, sizeof(int32));
    *N = input_integer;

    CHECK_FREAD(ret_val, "reading number of atoms");
    CHECK_FEOF(ret_val, "reading number of atoms");

Now I’m just getting back into c/c++ programming, and I never used macro’s much in the first place, but is this macro abuse?

I read this…
When are C++ macros beneficial?

…and it doesn’t sound like any of the kosher examples, so my guess would be “YES”. But I wanted to get a more informed opinion rather than just making educated guesses… 🙂

…errr, wouldn’t it be better to use some sort of wrapping?

  • 1 1 Answer
  • 1 View
  • 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-16T15:03:05+00:00Added an answer on May 16, 2026 at 3:03 pm

    Because it’s not the same. If you put the same thing into a function, you’ll have a short function that returns DCD_BADWRITE if X equals -1. The macro in question however returns from the containing function. Example:

    int foobar(int value) {
        CHECK_FREAD(value, "Whatever");
        return 0;
    }
    

    would expand to:

    int foobar(int value) {
        if (value == -1) {
            return (DCD_BADWRITE);
        };
        return 0;
    }
    

    If, however, it were a function, the outer function (foobar) would happily ignore the result and return 0.

    A macro that looks so much like a function, but behaves differently in a crucial way, is a major no-no IMO. I’d say yes, it is macro abuse.

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

Sidebar

Related Questions

I am reverse engineering some Java code into a class diagram. Now I'm wondering
I have some auto-generated hibernate DAO code which was generated by Eclipse-hibernate reverse engineering
Ok so I've recently started doing some reverse engineering, and I keep coming across
All what Hibernate reverse engineering generates is something like this @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name
Possible Duplicate: Protect .NET code from reverse engineering? we just develop a application with
Is it possible to configure Hibernate reverse engineering and code generation tool in such
I am doing some reverse engineering on a 3rd party program that is making
I've been contemplating how to protect my C/C++ code from disassembly and reverse engineering.
Some background to the problem: Reverse Engineering the DOM, Javascript events & "what's going
Possible Duplicate: Protect .NET code from reverse engineering? I want to make my software

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.