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
  • 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-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

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thats easy: change @drawable/ to @android:drawable/. Code completion didn't work… May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer Try !str.equals("x") !!! May 16, 2026 at 6:48 pm
  • Editorial Team
    Editorial Team added an answer It is highly recommended to avoid mutable structs. They exhibit… May 16, 2026 at 6:48 pm

Trending Tags

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

Top Members

Related Questions

I am reverse engineering some Java code into a class diagram. Now I'm wondering
I have decided that I really need to get some flowcharts for reverse engineering
Reverse engineering source code into a VS 2010 UML class model? I have a
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
Reverse engineering code and I'm kind of appalled at the style, but I wanted
Does visual studio 2010 unlimited modeling project do reverse engineering? How about code generation
I'm in the process of reverse-engineering a Windows executable. I found a class that
I have to analyse some existing Erlang code. Does anybody knows about a tool
I need to validate a form in php and display some error messages 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.