|
I didn't realize most preferred 'char* c' as opposed to 'char *c'. My initial intro to C was K&R so I started out with the former, but long ago switched to the latter, it just feels better somehow. I will say this in regards to 'char *c', though I realize this is wholly a religious debate and do not wish to antagonize, but it makes this look better: 'char *a, *b, *c;' Full disclosure, I use the 'goto' statement too.
|
|
|
|
|
Consider also multi level pointers:
char **ppCh;
char *c[];
etc.
|
|
|
|
|
.jpg wrote: char is a type and c is a name, to me, it always make more sense to put the name alone and have the type together, like "char* c", I can tell immediately that it is a pointer to a char, so its always goes like [type] [name].
But in contrast, most C/C++ code I found prefer the other way around, like "char *c". Is there any specific reasons why this is so?
My guess is that most C programmers hail from the K&R (Kernighan and Ritchie) days and I believe that char *c is the form they would have used. (I lost my dear old K&R years ago). Beyond that, it's probably just personal habit.
If you think hiring a professional is expensive, wait until you hire an amateur! - Red Adair
|
|
|
|
|
My $0.02.
In general variables are declared as:
type varname;
So ask the questions:
What is the type of varname?
What is the varname?
char c;
char* c;
double d;
float f;
double* d;
float* f;
Ultimately, BOTH ARE CORRECT.
As long as all devs in a team/organization use the same code format style guide, IT DOESN'T MATTER.
Just be consistent.
www.pointwise.com
|
|
|
|
|
Because that's how both the C and C++ grammars work. The asterisk binds to the thing being declared, not the type.
A declaration like
int* a, b;
is parsed as
int (*a), b;
Declarations in C (and simple declarations in C++) are a sequence of declaration specifiers followed by one or more (optionally initialized) declarators. The declarator is what specifies the name along with the the pointer-ness, array-ness, and/or function-ness of the thing being declared. Given a sequence of declaration specifiers D 1, then the following are all true:
D *p;
D a[N];
D f();
D *ap[N];
D *fp();
D (*pa)[N];
D (*pf)();
D (*fpa())[N];
D (*apf[N])();
The things following D are the declarators. *p is a declarator, as is a[N] , as is *ap[N] , as is (*pa)[N] . Since both [] and () operators have higher precedence than unary * , an expression like *a[N] parses as *(a[N]) . To declare a pointer to an array or a pointer to a function, you must explicitly group the * operator with the thing that points to the array or function.
This is why the common convention (at least among C programmers) is char *c; and not char* c; .
I understand where the type* name and type& name conventions came from in C++, and when I write C++ I follow that convention. But I feel dirty every time I do it.
1. Declaration specifiers include storage class specifiers like static , auto , and typedef , type specifiers like int , double , struct foo , and type qualifiers like const or volatile
modified 30-May-18 12:28pm.
|
|
|
|
|
To me, char* c looks badly formatted, same as if someone did x+ 3 .
Traditionally, I would use char *c , but after using java for several years, I prefer to use char * c now.
|
|
|
|
|
Because of this:
char *c, *p, a, *b, d;
or a better way to write that:
char *c = nullptr,
*p = nullptr,
a = 5,
*b = nullptr,
d = 10;
(it took out my tabs...)
modified 31-May-18 10:07am.
|
|
|
|
|
Replaced the blown PSU, put machine back together.
all running happily, 3 hours and counting.
Methinks OK, (these ASUS boards are meant to have some extra protection.)
Another backup - onto my new SSD external drive. Man these things are fast, and now well priced.
The only cheap thing in this build was the case + PSU combo, it failed, rest is fine.
Lesson learned: pay for the quality top-to-bottom. (It's my work machine).
Sub lesson learned: I'm never going to spin again. SSD Rocks!
Signature ready for installation. Please Reboot now.
|
|
|
|
|
And the next step after the PSU is the UPS (no not the delivery service)
|
|
|
|
|
They are well worth having!
Mine can (in theory) run my PC, two monitors, the NAS, and the router for an hour - in practice most powercust here last less than ten minutes, So I have ample time to save and shut down cleanly, and ride out the short cutouts we tend to get as "after shocks" once the power is restored.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 26-May-18 7:04am.
|
|
|
|
|
Quote: Mine can (in theory) ruin my PC Am I glad I don't have an UPS
|
|
|
|
|
Fixed ... but not so far from the truth.
Last century I was working at the weekend - we all were, big hardware contract and we were building kit like crazy - when we got a local ground strike by lightning. Fred was earthed at the time and he ... um ... noticed it.
Took out the telephone exchange, the fax, and the IDE card in every computer that was plugged into the mains, regardless of if it was powered up or not. 24 hours later and we we back up and running.
Not so the company down the road who has a big UPS to run their VAX. The lead/acid batteries exploded and sprayed the computer with sulphuric acid. Nasty.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: a big UPS to run their VAX. The lead/acid batteries exploded and sprayed the computer with sulphuric acid.
Sorry but I could only laugh when I read that.
Imagine how reassured they felt installing the UPS for just the sort of event.
Signature ready for installation. Please Reboot now.
|
|
|
|
|
For the next two weeks I will be keeping a low profile, going to Sicily to pay my respects to "il padrone". See if maybe I can interest him in my pirating skills.
So don't worry if I will be a bit quiet in the CodeProject forums
[Edit]
One of my tires was also keeping a low profile, it was flat, luckily discovered it before we had to go to Schiphol airport tomorrow and could change it in time !
modified 26-May-18 10:06am.
|
|
|
|
|
Quote: So don't worry if I will be a bit quiet Omertà, that's it.
Enjoy Sicily!
|
|
|
|
|
Grazie mille per il suggerimento
Started practicing my Italian on this nice site: Duolingo[^]
|
|
|
|
|
Nice!
|
|
|
|
|
Just make sure it isn't the day his daughter is to be married.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
RickZeeland wrote: going to Sicily to pay my respects to "il padrone"
He gave you an offer that you couldn't refuse?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Yes, he said come over here where it is nice and warm and we will drink Marsala wine
|
|
|
|
|
Quote: Prosecutors are increasingly treating overdose deaths as homicides, but they aren’t just going after dealers. Friends, family and fellow users are going to prison. ... As overdose deaths mount, prosecutors are increasingly treating them as homicide scenes and looking to hold someone criminally accountable. Using laws devised to go after drug dealers, they are charging friends, partners and siblings. The accused include young people who shared drugs at a party and a son who gave his mother heroin after her pain medication had been cut off. Many are fellow users, themselves struggling with addiction. [^]
So, you get a lawyer who proposes the "eggplant" defense: [^].
And, then : ?
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 26-May-18 7:17am.
|
|
|
|
|
Wow, that eggplant link was amazing even though there's no way that's gonna work. I'd try out the Chewbacca Defense[^]
|
|
|
|
|
But what was the eggplant doing there? I think this is the real question here!
|
|
|
|
|
Yes, every doctor is a murderer. Hang them all, and shoot the rest
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|