where is the definition of hex constant type in GCC

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

I always saw this kind of define, like:

#define  OS_MUTEX_KEEP_LOWER_8   0x00FFu

I guess here this 0x00FFu is defined as a unsigned.

where can I find the standard description for this?

Cheng

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are part of the 'C' standard. The u suffix defines the constant of being unsigned int, as you suspected. The suffix is not constrained to hex values only, it can be used with any supported number base.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Integer constants in decimal, octal, and hexadecimal notations are part of the C standard. It is described in K&R. You could also check out ANSI/ISO standards.

The official ANSI standard must be purchased. Here, though, is an excerpt from a draft of the standard, describing integer constants.
http://rm-f.net/~orange/devel/sp...

WinAVR extends this with integer constants in binary notation, following very similar rules.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Standardization of the C programming language has been transferred from
ANSI (“ANSI C89”) to ISO (“ISO C90”, “ISO C99”) meanwhile. While the
ISO also charges for its standards, there's a semi-official draft available
on the Web site of WG14 which is basically the latest standard, with the
currently two technical corrigenda (TC) already included:

http://www.open-std.org/jtc1/sc2...

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, thanks, i will check that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

by the way, is it always a good practice to have 'u' following those constant which should be always unsigned?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I don't think it good practice. But, keep in mind the rules of arithmetic in C. For example, you'll notice that F_CPU is usually something like 8000000UL to designate it as an unsigned long -- otherwise the C arithmetic with that value may done does as an integer -- which would obviously cause a problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so you mean i should just use it when it's needed, but not to put it everywhere?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's right; otherwise, it's just clutter if not needed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, thanks.