Deutsch English Français Italiano |
<vb6v1t$3b5mb$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!uucp.uio.no!fnord.no!news1.firedrake.org!nntp.terraraq.uk!nntp-feed.chiark.greenend.org.uk!ewrotcd!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams <thiago.adams@gmail.com> Newsgroups: comp.lang.c Subject: Code guidelines Date: Tue, 3 Sep 2024 09:22:20 -0300 Organization: A noiseless patient Spider Lines: 73 Message-ID: <vb6v1t$3b5mb$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 03 Sep 2024 14:22:21 +0200 (CEST) Injection-Info: dont-email.me; posting-host="15b67f073a3e4783414ee664431ab3cb"; logging-data="3512011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nsp4rF7kVUMAelWz1t3Gz8kuEZbsy1Sg=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:BeAnoiZ852ISZ5500Lv5LAUtk9Q= Content-Language: en-US Bytes: 2001 Witch style (F1, F2 ..) better represents the guidelines of your code? //The function f never returns nullptr int * f(); void F1() { int* p = f(); if (p == nullptr) { assert(false); return; } // using *p ... } void F2() { int* p = f(); assert(p != nullptr); // using *p ... } void F3() { int* p = f(); // using *p ... } void F4() { int* p = f(); if (p) { // using *p ... } } The same question but for struct members struct user { //Name is required, cannot be null. char * name; }; void F1(struct user* user) { if (user->name == nullptr) { assert(false); return; } // using user->name ... } void F2(struct user* user) { assert(user->name != nullptr); // using user->name ... } void F3(struct user* user) { // using user->name ... } void F4(struct user* user) { if (user->name) { // using user->name ... } }