The number is odd?

O

Old Wolf

Mark said:
Are you serious? What do you call # if not "pound"? I suppose you
could call it "sharp", but among people I know (not C# programmers)
everyone calls it "pound". Is this a geographical thing? (I'm in the U.S.)

Everyone I know calls it "hash". This is particularly
appropriate for describing the language "C hash" too.
 
I

Ian Collins

Mark said:
Are you serious? What do you call # if not "pound"? I suppose you
could call it "sharp", but among people I know (not C# programmers)
everyone calls it "pound". Is this a geographical thing? (I'm in the
U.S.)

You obviously haven't used a UK keyboard, where shift3 is the £ (GBP)
symbol. # is hash.
 
M

Mark P

Old said:
Everyone I know calls it "hash". This is particularly
appropriate for describing the language "C hash" too.

But what about the language C tic-tac-toe-board?

Where in the world are you located?
 
V

Victor Bazarov

Mark said:
But what about the language C tic-tac-toe-board?

Where in the world are you located?

It's a view on the world from a gaol cell. The language is
"See, gaoled!"

V
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

david said:
(number & 1) is synonym to (number % 2), the remainder of the division by 2.

I was thinking the logic & operator would be at least as fast as % (modulo).

The !! is there to convert a scalar to a bool, but it may be unneeded,
especially in this case where the result is only 0 or 1.



This is ok, but your reasons are unclear to me:
Is this preferred/cleaner/mandatory to initialize a bool ?
int x = 3; int x(3); aren't they identical ?
bool is not a basic type ?

They are identical. It was the lack of the double '!' that I was
referring to.

bool odd = ( number & 1 );


K
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

Frederick said:
Kirit Sælensminde:



!!a

is short-hand for:

(bool)a




Because it's dressed up to look like you're passing an argument to a
constructor. Intrinisc types are distinct from user-defined types... don't
lump them into the same category and come out with bastardisations such as:

int i(1);

, it just looks stupid, plus it makes one have to consider the "if it looks
like a declaration" rule.

I'm not sure that I agree with you on that. The important distinction
between the types we use is whether they follow object or value
semantics, not whether they happen to be in the sub-set of types that
happen to be defined by keywords in the standard.

std::string s( "Hello" );

Presumably you consider the above OK? It invites equal consideration to
the "if it looks like a declaration" rule.


K
 
J

Jack Klein

(number & 1) is synonym to (number % 2), the remainder of the division by 2.

No, it is not. Not for integer types with negative values on 1's
complement systems, which the C++ language specifically supports.
 
M

Michal Nazarewicz

Geo said:
What's the point any way since implicit conversion to bool is going to
happen for the assignement in the same way that it would happen for the
'!' !!!.

In this particular reason it will but consider a code:

#v+
int arr[10] = { /* some initial values */ };
int num = 0;
for (int i = 0; i<10; ++i) num += arr % 2;
#v-

counting how many odd numbers there are in arr. It'll fail since
arr%2 may return -1 so here you have to cast it, use !! or ?: and
!! is the shortest form.
 
F

Frederick Gotham

Kirit Sælensminde:
std::string s( "Hello" );

Presumably you consider the above OK?


I use the form for two reasons:

(1) It looks like a function call/constructor call.
(2) It doesn't require a copy-construct as does the other form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top