Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Oct 2011 16:51:35 -0500 (CDT)
From:      Robert Bonomi <bonomi@mail.r-bonomi.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: need to check for hex in C: how/
Message-ID:  <201110162151.p9GLpZHZ064824@mail.r-bonomi.com>
In-Reply-To: <20111016212628.GA30284@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> From owner-freebsd-questions@freebsd.org  Sun Oct 16 16:27:46 2011
> Date: Sun, 16 Oct 2011 14:26:31 -0700
> From: Gary Kline <kline@thought.org>
> To: FreeBSD Mailing List <freebsd-questions@freebsd.org>
> Cc: 
> Subject: need to check for hex in C: how/
>
>
> if n == 15 and x is the int. i can say 
>
> if ((int)x == 15)  Or to check if x == 'A' i can cast x to (char)x.
>
> what's the syntax to chec if x is , say, 32/

The advice from my computer-science professor was 'try it and find out'.

It doesn't matter what anybody _says_ it is, the only thing that 
matters is what the computer (or, to be precise, the compiler) accepts?

Now, for some information that you could/should get from any elementary
book on C programming ("The C Programming Language", by Kerningan and
Ritchie [r.i.p., this last week] is recommended):

In general, you don't need _any_ explicit casts for those situations.

C does 'automatic' promotion of numeric items so they have comparable 
'width' for comparisons.

For more details, see the 'fine manual' mentioned above.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110162151.p9GLpZHZ064824>