Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Why I Hate C
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kaz Kylheku  
View profile  
 More options Sep 21 2012, 3:13 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@kylheku.com>
Date: Fri, 21 Sep 2012 19:13:00 +0000 (UTC)
Subject: Re: Why I Hate C
On 2012-09-21, kalvin.n...@gmail.com <kalvin.n...@gmail.com> wrote:

> torstai, 20. syyskuuta 2012 18.36.26 UTC+3 Nick Keighley kirjoitti:
>> > typedef enum
>> > {
>> >     BITMASK_1 = 0x01,
>> >     BITMASK_2 = 0x02,
>> >     BITMASK_3 = 0x04}
>> > Bitmask;

>> #define BIT(N) (1 << (N))

> This typedef is just fine. Its intention is to declare a enumerated constant
> values for the bitmasks. No problem here.

Yes there is a problem. What are you daft?

The enumerated type has three values in its domain: BITMASK_1, BITMASK_2
and BITMASK_3.   A value such as BITMASK_1 | BITMASK_2 is not in the
domain of the enumerated type.

Yet the code uses that type to represent it:

   Bitmask x = BITMASK_1 | BITMASK_2;

What that means is that x now has a value which is not one of the declared
constants, and therefore outside of the type.

Note that this was banished from C++ long ago, because C++ was given
type-safe enumerations.

That's one good reason to write your C in such a way that it also compiles with
a C++ compiler.

You cannot use enumerations for bitmasks, period. It's conceptually wrong,
and banished by the better dialect of C known as C++.

>> > typedef enum
>> > {
>> >     ONE,
>> >     TWO,
>> >     THREE}
>> > Number;
>> well yes I admit i'd puke over that one. Everyon knows its

> This is just fine as well. The intention is to declare enumerated constants
> with type identifier Number.

No it is not fine, because now you have constants ONE, TWO, and THREE
whose values are 0, 1 and 2, respectively.

I suggest you read a C tutorial.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.