Re: Code guidelines

Liste des GroupesRevenir à cl c  
Sujet : Re: Code guidelines
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 03. Sep 2024, 17: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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
3 Sep 24 * Code guidelines22Thiago Adams
3 Sep 24 +* Re: Code guidelines19David Brown
3 Sep 24 i`* Re: Code guidelines18Thiago Adams
3 Sep 24 i +* Re: Code guidelines4David Brown
3 Sep 24 i i`* Re: Code guidelines3Thiago Adams
3 Sep 24 i i +- Re: Code guidelines1David Brown
3 Sep 24 i i `- Re: Code guidelines1Chris M. Thomasson
3 Sep 24 i `* Re: Code guidelines13Thiago Adams
3 Sep 24 i  `* Re: Code guidelines12David Brown
3 Sep 24 i   `* Re: Code guidelines11Thiago Adams
3 Sep 24 i    +* Re: Code guidelines5Thiago Adams
4 Sep 24 i    i`* Re: Code guidelines4David Brown
4 Sep 24 i    i `* Re: Code guidelines3Thiago Adams
4 Sep 24 i    i  +- Re: Code guidelines1Thiago Adams
4 Sep 24 i    i  `- Re: Code guidelines1David Brown
4 Sep 24 i    +* Re: Code guidelines3David Brown
4 Sep 24 i    i`* Re: Code guidelines2Keith Thompson
4 Sep 24 i    i `- Re: Code guidelines1David Brown
4 Sep 24 i    `* Re: Code guidelines2Kaz Kylheku
4 Sep 24 i     `- Re: Code guidelines1David Brown
3 Sep 24 +- Re: Code guidelines1Kaz Kylheku
3 Sep 24 `- Re: Code guidelines1Blue-Maned_Hawk

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal