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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:04:29+00:00 2026-05-16T06:04:29+00:00

Where are MIN and MAX defined in C, if at all? What is the

  • 0

Where are MIN and MAX defined in C, if at all?

What is the best way to implement these, as generically and type safely as possible? (Compiler extensions/builtins for mainstream compilers preferred.)

  • 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-16T06:04:30+00:00Added an answer on May 16, 2026 at 6:04 am

    Where are MIN and MAX defined in C, if at all?

    They aren’t.

    What is the best way to implement these, as generically and type safe as possible (compiler extensions/builtins for mainstream compilers preferred).

    As functions. I wouldn’t use macros like #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)), especially if you plan to deploy your code. Either write your own, use something like standard fmax or fmin, or fix the macro using GCC’s typeof (you get typesafety bonus too) in a GCC statement expression:

     #define max(a,b) \
       ({ __typeof__ (a) _a = (a); \
           __typeof__ (b) _b = (b); \
         _a > _b ? _a : _b; })
    

    Everyone says “oh I know about double evaluation, it’s no problem” and a few months down the road, you’ll be debugging the silliest problems for hours on end.

    Note the use of __typeof__ instead of typeof:

    If you are writing a header file that
    must work when included in ISO C
    programs, write __typeof__ instead of
    typeof.

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

Sidebar

Related Questions

I'd like to generate an array of Random numbers with defined Min, Max, Mean
Is there a way to find out the number of digits of min/max values
Possible Duplicate: Find the min number in all contiguous subarrays of size l of
I`ve a dictionary defined like this : d = {date: tuple(date),open:tuple(open),close:tuple(close),min:tuple(min),max:tuple(max),MA:tuple(ma)} Each one of
i have defined a method like this: private String getRadndomNumber(int min, int max) {
As a continuation of my min/max across an array of objects I was wondering
I have set my java min/max heap size to be the same as outlined
params.max = Math.min(params.max ? params.int('max') : 2, 100) orders=OrderInfo.createCriteria().listDistinct() For pagination, we need to
I have a search form with min and max fields. It queries a MySQL
This is my function: Random(int min, int max) { srand(time(NULL)); return (rand() % (max-min))

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.