Are these the best set of bitset macros in the world or what!?

B

Brian

Ian said:
Why use macros at all?

I mistyped that. I use typedefs (as I wrote in a prior post). Why I did
the macro thing on the bitsetX thing, I don't know. Brain fart I guess.
Pointless.

Hardly. See my other post for a couple of valid points.
That's neither C, no C++. Unless you are using more silly macros. In
C++ there no need to use macros for bit manipulation.

That is indeed C++ the way I use it. You may use 'inline' and 'bool' if
you wish, I don't.

In my library code. I changed it for the post to avoid all the ranting
about that, as I wanted to focus on the other things.
 
B

Brian

Eric said:
Barry said:
[...]
And what happens if you want to test the sign bit? You might avoid
syntax errors and undefined behavior with
#define bit(n) (1u<< (n))

While I don't see the need, some might even want 1lu or 1llu.

OK on 1u. But the compiler wouldn't really change to signed if an
unsigned was passed (guaranteed with use of the bitsetX defines
below), would it?

You're *still* not seeing the problem, are you? All, right,
let's go through it step by step:

- What is the type of `1'?

I would assume it would be "coerced" to the type of n, yes? OK, not for
the uint8 and uint16: C's conversion/promotion rules suck rocks. Good
thing I have these macros to make things less error-prone than the raw
syntax. A hundred more of them and C may even be turned into something
good.
- How many non-padding bits are in the type of `1' (on any
given implementation, obviously, since C does not specify
a maximum for this quantity)?
- Call that bit count B. What happens if `n >= B'?
- Returning to the type of `1': Is it a signed or an unsigned
type? - If it happens to be a signed type, what happens if `n >= B-1'?


Perhaps C++ lacks C's <stdint.h> header, and the rest of us are
spoiled by not having to put up with C++'s limitations.

Rant noted.
"Beautiful new impediments to understanding," as the annotations
to the Ten Commandments put it.

Try something new. You'll like it (unless you like vi!). C is an
impediment to understanding that's why a programmer needs macros to make
it understandable.

?
 
B

Brian

Eric said:
With the definition given, and even if `n' is a single identifier
or constant, the programmer's knowledge helps not one whit. Damage
already done, the moving finger writes, try to do it better yesterday.

I was obviously not looking at my own code as the free-standing macros
obviously don't don't pass the bitsetX things to bitn. Find the post
where I showed the inline function that uses the low-level macros to good
effect and you'll better understand the usage of the macros.
 
B

Brian

Ben said:
What's the benefit of these macros? How is
setbit(x, n)
easier to read or to write than
x |= 1 << n;

Surely you are joking! Give each to a student in programming 101 without
any instruction and see the results. You don't need to have the car
engine exposed to drive the car. Low-level cryptics are not important,
productivity is. Abstraction rules (else use machine language directly).
 
I

Ian Collins

That is indeed C++ the way I use it.

As I said elsewhere, you don't have to resort to macros for bit
manipulation in C++.
> You may use 'inline' and 'bool' if you wish, I don't.

So your C++ is as obscure as you C? Yet another team player I see.
 
B

Brian

Ian said:
No, neither does C++.

I just care that my compiler does. In either case, the relevant thing was
not the ugly platform or language things, but rather the very nice
looking typedefs such as uint32. MMMmmmm good!
 
B

Brian

Ian said:
As I said elsewhere, you don't have to resort to macros for bit
manipulation in C++.

I like it that way.
So your C++ is as obscure as you C? Yet another team player I see.

I have larger goals than those of standard C programmers so I can't be
held back by the language's limitiations and idiosynchracies. I also
believe that C/C++ can be useful (without all the drudgery) if one knows
how to harness it and that is exactly what I am doing.
 
S

Seebs

The macros are clearer and less error-prone.

No, they aren't. They're less clear. In particular, they have connotations
which are familiar to many programmers, but not to you.

.... Which is to say: They may seem clearer to you. If you never, ever,
want to write code for anyone else, that's fine. If you ever want to write
code which any other person may have to maintain, though, you have to look
into what is clearer *to other people*.

Someone who is experienced in C is going to immediately understand == and
!=. They may well not have any idea what eq and ne are supposed to be.
If they've got experience with perl or shell (common languages for C
programmers to know), they may expect that ne and eq have DIFFERENT
SEMANTICS from != and ==, because that's what those names have been
historically used for.
Anyone who couldn't figure out from the context what those macros meant
need not be doing any coding IMO.

I don't think you understand.

I can guess what they *probably* *should* mean. Probably. I cannot,
however, predict what madness may have driven someone to create them.

If I know that you are the sort of person to use "ne" for !=, I also know
that you are the sort of person to do all sorts of insane things I cannot
reasonably predict. Therefore, I have to go look and see what you did.
Good thing my code is not for anyone else huh.

Silly me. I thought you were posting these because you thought someone
else might use them. Nevermind; I realize now that you have no interest
in working with other people, making anything you could possibly say about
programming of no interest to, well, anyone.

I can't, but... I can tell you that I'd never hire you, and if I ever
by some mischance happen to see your name on a list of candidates, it won't
get to the interview stage.
Anything that cleans up ugly C syntax is a boon. I'll further
that and say those who don't create things to abstract away the low level
are not very good coders, or JUST coders. Everything implemented at level
0 is not a good design for any software. C is just a hammer. If you want
more tools, then you have to create them. The couple of macros above are
just tidbits.

They are *shitty* tidbits.

Seriously, I've written a ton of tools for abstracting C. What you're
doing, for the most part, is not abstracting much of anything.
C is inherently obfuscated ("cryptic"). Keywords would be better than the
operators and with the macros, I have the equivalent.

Again, this dooms your macros to be never usable by anyone but you.
You can't use code other people wrote, because if you include your
macros, it will break their code -- both "ne" and "eq" are names that
people use for variables in other code. Other people can't use your
code. You have isolated yourself from any possible interaction with
or cooperation with other programmers.
The macros above
are a teeny tiny step to clean up the langugage.

Trying to turn C into another language doesn't clean it up.
C++ actually defines
macros in the standard such as those, I believe, and like I said, in
these modern times of syntax-highlighting editors, those macros really
come into their own. Try it, your code will look much nicer, be more
readable in that IDE and be less error-prone too. :)

I don't use IDEs. :) Anyway, I just don't believe you. In the last
twenty years of C programming, I don't think I've ever had an error which
could have conceivably been avoided by such macros, but I've seen plenty
of places where they'd have caused problems.
Not if you abstract it away properly.

And therein lies the problem:

You can't, in fact, abstract it away enough to get away from that reality
in C. You can in C++, probably. But in plain C, you will never get away
from this:
*p == p[0]

Any attempt to not count from zero will screw you, because the language
really DOES count from zero. You can write up elaborate macros and
specialized helper functions all you want, but if you're ever going to
use pointers, you will be stuck with a language which counts from zero.

But, on the whole, the question is irrelevant. You are staunchly and
militantly opposed to anything that could lead to cooperation with other
people, you don't care whether your code is useful to other people,
and you haven't yet realized that it could be useful to you to be able to
use other people's code. That, plus the insulting and dismissive tone,
advises me clearly that the time has come to apply lossless compression
to your tiny part of Usenet's signal. *plonk*

-s
 
I

Ian Collins

I have larger goals than those of standard C programmers so I can't be
held back by the language's limitiations and idiosynchracies. I also
believe that C/C++ can be useful (without all the drudgery) if one knows
how to harness it and that is exactly what I am doing.

Ah, another who's ego dwarfs his abilities.
 
L

luserXtrog

The macros are clearer and less error-prone.

When present, maybe.

Anyone who couldn't figure out from the context what those macros meant
need not be doing any coding IMO.

Figuring from context is different from knowing for sure.

Good thing my code is not for anyone else huh.

A likely criterion for "best set of ... macros in the world"
is "useful to more than one person".
 
K

Keith Thompson

Brian said:
The macros are clearer and less error-prone.


Anyone who couldn't figure out from the context what those macros meant
need not be doing any coding IMO.

Eye sea. Sew if yew don't laik thu langwidge yur yusing, u cann
djust uze yur owne rulz too maek it beter, and reeders wil figger
it owt. Eye'll kiep that in mynd.
 
L

luserXtrog

Eye sea.  Sew if yew don't laik thu langwidge yur yusing, u cann
djust uze yur owne rulz too maek it beter, and reeders wil figger
it owt.  Eye'll kiep that in mynd.

Perhaps we should call it BabyTalk.
 
F

Felix Palmen

* Brian said:
Make me. :p Anything that cleans up ugly C syntax is a boon. I'll further
[...]

Uhm, *plonk*, for there's obviously nothing sensible to expect here.
 
B

Brian

Seebs wrote:

[snip]

Your entire post and every "point" in it was a strawman. (Seems to be a
pattern in this ng, for I've found 2 in just reading very few posts. I
hope you and the other guy are just squeeky wheels and not representative
of the whole group).
 
B

Brian

Ian said:
Ah, another who's ego dwarfs his abilities.

Just because you can't doesn't mean that anyone else can't. Don't worry,
you can continue to program in C. No one is going to make you change your
religion.
 
B

Brian

luserXtrog said:
When present, maybe.



Figuring from context is different from knowing for sure.



A likely criterion for "best set of ... macros in the world"
is "useful to more than one person".

Use if you wish. It's not like I invented anything other than short
names. Doing it once and wrappering it is loads better than being at the
lowest level all the time. That indeed is what programming is all about.
Just because standard C is fixed in stone doesn't mean anyone has to be
limited by that.
 
B

Brian

Keith said:
Eye sea. Sew if yew don't laik thu langwidge yur yusing, u cann
djust uze yur owne rulz too maek it beter, and reeders wil figger
it owt. Eye'll kiep that in mynd.

I see that thinking outside of the box strikes a chord with many people
in here. How does building on the C standard baseline threaten you? Do
tell, I really want to know. The only guess I can come up with is that
your job is based upon the idosyncratics/esoterics rather than fixing
them and that you wouldn't want to fix them if you could. Is that it?
Seriously, a few clarifying macros and the world is tipped off of its
axis it seems.
 

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

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top