Sujet : Re: Code guidelines
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 03. Sep 2024, 16:10:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240903080407.654@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-03, Thiago Adams <
thiago.adams@gmail.com> wrote:
Witch style (F1, F2 ..) better represents the guidelines of your code?
>
>
//The function f never returns nullptr
int * f();
^^^^^^
Nope.
void F1() {
int* p = f();
^^^^
Nope.
>
if (p == nullptr) {
assert(false);
return;
}
// using *p ...
}
>
void F2()
{
int* p = f();
^^^
Nope.
assert(p != nullptr);
// using *p ...
}
>
void F3()
{
int* p = f();
^^^^
Nope.
// using *p ...
}
>
void F4()
{
int* p = f();
And nope.
The syntax of a declaration is, roughly, "specifier-list
comma-separated-declarators".
"int" is the specifier list, "*p" is the declarator.
Your style invites optical illusions like:
int* a, b; // two pointers?
int *a, b; // Nope: actually this.
In C, declarators are type-constructing expressions which (at least in
their basic, unadorned forms) resemble how the name will be used.
For instance when you see "int a[3], *p", you can
interpret it as saying that "the expressions a[3] and *p
shall have type int".
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca