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


Groups > comp.lang.c > #19849

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

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Generates integer literal of the largest value a variable can hold. Macro takes only variable-name.
Date 2012-04-23 17:01 -0400
Organization A noiseless patient Spider
Message-ID <4F95C335.8090509@verizon.net> (permalink)
References <3b194163-c8e2-4250-864a-d3f0a1324677@f5g2000vby.googlegroups.com> <858f1f2a-5c55-439b-b83d-3d4d6efcb150@f5g2000vby.googlegroups.com>

Show all headers | View raw


On 04/23/2012 04:28 PM, John Reye wrote:
> Ahh that C's right?
> 
> Sortof slightly "statically typed".
> Then then they throw in integer promotions to ease writing code in
> some cases, but causes novice programmer's bugs and kills the type-
> system in other cases.
> 
> Writing portable C-code that works across different word-sizes must be
> a real horror!

Not really. If you need exact or minimum sizes, using the size-named
types from <stdint.h>. If you need C90 capability (or just want to use
shorter type names), think of [un]signed char as essentially the same as
[u]int_least8_t, [unsigned] short as [u]int_least16_t, [unsigned] int as
[u]int_fast16_t, and [unsigned] long as [u]int_least32_t. Except, of
course, that they're not required to have 2's complement type, and
(except for unsigned char) are allowed to have padding bits.

I won't claim it's trivial to deal with all of these issues, but it's
not a horror. Careful use of the corresponding MIN and MAX macros from
<stdint.h> or <limits.h> respectively, will deal with most of the
relevant problems.

If you want a language that guarantees more about it's fundamental types
than C does, try Java; but keep in mind the efficiency penalties of
using a type guaranteed to be exactly 16 bits on a 32-bit machine (or
vice versa). If that inefficiency doesn't bother you, and the
corresponding uncertainty about whether 'int' has 16 or 32 bytes does,
then C is definitely NOT the language for you.

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