|
Said well.
Here is a C sample using pointers.
Using my rule of keeping pointers from being too saltly, I keep them at a somewhat controlled level
(this is mostly pseudo code so don't cry foul if you see syntax boo-boos
and/or use it and it crashes).
The point is pointers can be very powerful, but must be used with care and with restraint.
/* entry points for routines that do something */
extern int sub1();
extern int xyz();
extern int abc();
extern int subx();
/* put their addresses into a table */
...
struct { int (*action)() } cmd[] = {
sub1,
xyz,
abc,
subx
};
...
int execute_command( char *arguments )
{
int (*go)();
int err;
/* determine index i into the address table using whatever parsing is need to
identify the command intended by the user or the system
*/
go = (int (*)()cmd[i];
/* execute the routine selected by index i */
err = (*go)( arguments );
/* returns error code */
return( err );
}
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
This is just one way of many ways to slice the watermelon.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
I'm probably not going to get into jump tables in my article, but you'll be able to create them by building on the techniques I present.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I am not C++ expert, but as I understand it, C is a subset of C++, ergo, anything you can do in C, one can do in C++. This might not be 100% true, but pointers for sure.
"A little time, a little trouble, your better day"
Badfinger
modified 18-Jun-22 19:37pm.
|
|
|
|
|
jmaida wrote: I am not C++ export I'm as much export as you.
How is it relevant that you are an export?
Assuming you know perpendicular lines, explain .NET without the term "reference".
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
fixed
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
You're fixed? How is that gonna help?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I edited the post to fix typo.
Done
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
look forward to your article
diligent hands rule....
|
|
|
|
|
In 1980, I was introduced to pointers (by way of Pascal). They made perfect sense to me then as they do now.
/ravi
|
|
|
|
|
I was introduced to pointers using PL/I in grad school. Very cool language. Not quite as down and dirty as C, but the compiler general kept it clean. Amazing optimizing compiler and a great language syntax. Too bad it was IBM OS system language so proprietary at the time. C slowly became the go to language at the time for me. Pascal was very nice. Clean and clear. But I went the C route.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
I remember PL/1. My graduate CS program decided to instead use Pascal, and then switched to C. We're probably of the same vintage. I completed my MS (CS) degree in 1984.
/ravi
|
|
|
|
|
I completed my MS in 1978. (MSMCD) MS in Mathematics-Computer_Science-System_Design one of the first to offer a sort of triple major. The grad school was pretty young and small so they spread us around various faculty specialties to keep everyone busy. Loved it. It even included some courses in digital electronics. Did you do an wire-wrapping of circuits?
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
jmaida wrote: Did you do an wire-wrapping of circuits? Yes, because I transferred from an MS (Physics) program, I was required to take a few undergrad courses in digital circuit design. We were given a "breadboard in a suitcase" that included a PSU, clock, input switches and output LEDs, and our assignments were implemented as wire wrapped circuits on the suitcase. I have very fond memories of those days! Some of my most fun courses were Assembly Language and Compiler Construction I and II, and my Master's theses. (I got permission to do two because I was working under two professors.)
/ravi
|
|
|
|
|
Yup, we had similar experiences. We used a similar breadboard in a suit case product with similar I/O stuff. Compiler design was a favorite. Still use some the techniques in code, especially parsing user inputs. Did not do much actually assembly coding, but as part of the compiler design courses, we had to create our own assembly language and a simulator written in Fortran, running on a Data General Eclipse mini-computer (not so mini by today's std) about 1 computer rack in size, to execute it. Did many an all-nighter. Went from punch cards to dumb terminals to micro-computers. I worked in the same lab after graduating so my experiences there spanned into the early 80's. Good times indeed.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Looking forward. You have a knack at getting to the core of things. Thanx.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Thanks, I try. It's going to take me longer than usual it seems. It's a pretty involved topic, and I have to take breaks. It's not so much that it's long, but there are a lot of angles to cover and if I don't clear my head periodically I forget to include some.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I agree.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
If you article includes C++ smart pointers you should include guidelines such as Herb Sutter's guidelines...
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
Wordle 364 4/6
🟨⬜⬜⬜⬜
⬜🟩⬜🟨⬜
🟩🟩⬜⬜🟩
🟩🟩🟩🟩🟩
Had to look up for this word. Not heard earlier.
|
|
|
|
|
Wordle 364 5/6
🟨⬜⬜⬜⬜
⬜🟨⬜⬜⬜
⬜⬜⬜⬜⬜
⬜🟩⬜🟨⬜
🟩🟩🟩🟩🟩
More subtractive than additive today!
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Not an easy one!
Wordle 364 4/6
⬜⬜⬜⬜🟨
⬜🟨⬜🟩⬜
🟨⬜⬜🟩⬜
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 364 4/6
⬜⬜⬜🟩⬜
⬜🟩⬜🟩⬜
⬜🟩🟩🟩⬜
🟩🟩🟩🟩🟩
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
The thread below was auto cleansed to remove a closed spam message, and the thread attached to pkfox's.
I was not and am not accusing pkfox, it's an "oddity" of the new CP system for spam message handling: Bugs and Suggestions[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|