C & hardware

K

Keith Thompson

Nick said:
Although you can at least avoid including the header if you don't want
them in the namespace.

But unless the standard specifically says they're macros and not
functions, their names would be reserved for use as identifiers
with external linkage.
 
J

James Dow Allen

On the topic of rotates,

It is much easier to add a few extra ops into a language and not use them
very often, than to leave them out and have to rely on tricks by programmers
and compiler writers.

I must have missed the part where someone explained where rotate
is useful in the first place. I can see it for hash functions;
where else? (I'm not saying there's no use, just that it's rare.
I've used them myself, I'm sure, decades ago, but don't remember
why and I'm sure it was quite rare.)

Speaking of compiler support for commonly used ops,
what about
q = a / b;
r = a % b;
also doable as
struct { long q, r; } res = ldiv(a, b);
or whatever it is.

When I tried the above on gcc, I found that
with the first form, gcc avoided the redundant
division, but with the second it didn't!!!!!!
Exactly opposite to what one might expect!
Did I do something wrong ????

James
 
N

Nick

Keith Thompson said:
But unless the standard specifically says they're macros and not
functions, their names would be reserved for use as identifiers
with external linkage.

You get round that with the _bool trick. Just have all the functions
with names starting with _ (or - for that matter - with E or str, or any
of the other infinite chunks of namespace the standard already reserves
for itself) and your header has a pile of #defines to turn them into the
right name.

#define rotleft Erotleft
#define rotright strrotright
#define shakeitallabout _something
 
M

Mok-Kong Shen

James said:
I must have missed the part where someone explained where rotate
is useful in the first place. I can see it for hash functions;
where else? (I'm not saying there's no use, just that it's rare.
I've used them myself, I'm sure, decades ago, but don't remember
why and I'm sure it was quite rare.)

It's e.g. in RC5.

M. K. Shen
 

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
474,083
Messages
2,570,589
Members
47,211
Latest member
JaydenBail

Latest Threads

Top