| Deutsch English Français Italiano |
|
<20240903080407.654@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: Code guidelines
Date: Tue, 3 Sep 2024 15:10:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <20240903080407.654@kylheku.com>
References: <vb6v1t$3b5mb$1@dont-email.me>
Injection-Date: Tue, 03 Sep 2024 17:10:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="009eeee9eb186b8e4806da932904b8ba";
logging-data="3561056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qbxPdBAJMhrZ5Cbl37Hs/4tX7gVezfDs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:B8QlgVBeyvY3PALowylMwpO/Qis=
Bytes: 2166
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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca