Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #20374

Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name.

Message-ID <4FA37EA0.50003@loria.fr> (permalink)
Date 2012-05-04 09:00 +0200
From Jens Gustedt <jens.gustedt@loria.fr>
Newsgroups comp.lang.c
Subject Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name.
References <3b194163-c8e2-4250-864a-d3f0a1324677@f5g2000vby.googlegroups.com> <a047e22e-f4ec-49bb-b6ce-5cb08b616c07@cl4g2000vbb.googlegroups.com>
Organization Guest of ProXad - France

Show all headers | View raw


Am 05/04/2012 12:35 AM, schrieb John Reye:
> Here's a nice hack for... getting the max value for any unsigned type:
> from "unsigned char" to "unsigned long long":
> 
> #include <stdio.h>
> #include <limits.h>
> 
> #define GET_TYPE_INT_OR_LARGER_0(var) (var & 0)
> 
> #define GET_SHIFT_CHAR_BIT2(var) ((sizeof(var) >= sizeof(int)) ? 0 :
> (CHAR_BIT * (sizeof(int)-sizeof(var))))

> ....

> What do you think?
> 
> Does the macro GET_MAX_UNSIGNED_RVALUE() really create a literal?
> (i.e. something that can be used in #if ... preprocessing)
> Or does it depend on the compiler?

no

- IIRC ternary expressions are not allowed in the preprocessor
- sizeof is not evaluated in the preprocessor

Jens

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. John Reye <jononanon@googlemail.com> - 2012-04-23 12:38 -0700
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. Thomas Richter <thor@math.tu-berlin.de> - 2012-04-23 22:08 +0200
    Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. James Kuyper <jameskuyper@verizon.net> - 2012-04-23 16:45 -0400
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. John Reye <jononanon@googlemail.com> - 2012-04-23 13:28 -0700
    Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. James Kuyper <jameskuyper@verizon.net> - 2012-04-23 17:01 -0400
    Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-04 00:30 -0700
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. Ben Pfaff <blp@cs.stanford.edu> - 2012-04-23 13:36 -0700
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. James Kuyper <jameskuyper@verizon.net> - 2012-04-23 17:11 -0400
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. John Gordon <gordon@panix.com> - 2012-04-23 22:03 +0000
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. John Reye <jononanon@googlemail.com> - 2012-05-03 15:35 -0700
    Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. Jens Gustedt <jens.gustedt@loria.fr> - 2012-05-04 09:00 +0200
      Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. James Kuyper <jameskuyper@verizon.net> - 2012-05-04 07:54 -0400
  Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name. Tim Rentsch <txr@alumni.caltech.edu> - 2012-05-07 21:40 -0700

csiph-web