Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #100881

Re: guidelines for pointer check

From Noob <root@127.0.0.1>
Newsgroups comp.lang.c
Subject Re: guidelines for pointer check
Date 2017-01-02 17:35 +0100
Organization A noiseless patient Spider
Message-ID <o4dvdt$nnb$1@dont-email.me> (permalink)
References <4598b1a6-e647-4327-85d8-23f83198d0c6@googlegroups.com> <o4djuk$ebt$1@dont-email.me> <o4dkf4$g93$1@dont-email.me>

Show all headers | View raw


On 02/01/2017 14:28, David Brown wrote:
> On 02/01/17 14:19, Noob wrote:
>> On 29/12/2016 21:53, Thiago Adams wrote:
>>
>>> Do you have some style guideline for pointer checking?
>>>
>>> This is a kind of poll:
>>>
>>>
>>>    //Style 1
>>>    if (pVariable) { /*...*/ }
>>>
>>>    //Style 2
>>>    if (pVariable != NULL)  { /*...*/ }
>>>
>>>    //Style 3
>>>    if (pVariable != 0) { /*...*/ }
>>>
>>> Do you dislike one of them?
>>> Do you use only one of them?
>>> Do you use more than one?
>>> Other?
>>
>> Slightly different situation, same question:
>>
>> void foo(int **p)
>> {
>>   if (*p == NULL) ...
>>   if (*p == 0) ...
>>   if (!*p) ...
>>
>> which would you use?
>>
>> In my opinion, the last one is truly awful, because it's not always
>> easy to spot the '!' between '(' and '*' in all fonts. And some
>> coding guidelines unhelpfully disallow a space after '('.
>>
>> Regards.
>>
> 
> I would not use any of them as they stand - at first glance, they look
> like mistakes.  I would want more context, proper names, and maybe even
> typedef's depending on the situation - and then the "best" arrangement
> would depend on the details.
> 
> Other possibilities that you have missed include:
> 
> 	int * q = *p;	// Using better names, of course...
> 	if (q = NULL) ...
             ^^^
Fail ;-)

Here's the /actual/ situation I had in mind:

void aux_read(void *chip, u8 **buf, int len, int *pos)
{
	*pos += len;

	if (*buf == NULL) {
		/* skip over "len" bytes */
		cmdfunc(chip, CMD_RNDOUT, *pos, -1);
	} else {
		read_buf(chip, *buf, len);
		*buf += len;
	}
}

Regards.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-29 12:53 -0800
  Re: guidelines for pointer check Ian Collins <ian-news@hotmail.com> - 2016-12-30 09:58 +1300
  Re: guidelines for pointer check Keith Thompson <kst-u@mib.org> - 2016-12-29 13:39 -0800
    Re: guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-29 15:24 -0800
      Re: guidelines for pointer check Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-29 19:05 -0500
        Re: guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-30 05:27 -0800
          Re: guidelines for pointer check Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-30 14:35 +0000
          Re: guidelines for pointer check supercat@casperkitty.com - 2016-12-30 10:38 -0800
        Re: guidelines for pointer check Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-02 02:28 -0800
      Re: guidelines for pointer check Keith Thompson <kst-u@mib.org> - 2016-12-29 16:19 -0800
  Re: guidelines for pointer check Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 13:58 -0800
  guidelines for pointer check asetofsymbols@gmail.com - 2016-12-30 05:35 -0800
  Re: guidelines for pointer check raltbos@xs4all.nl (Richard Bos) - 2017-01-01 10:47 +0000
  Re: guidelines for pointer check Noob <root@127.0.0.1> - 2017-01-02 14:19 +0100
    Re: guidelines for pointer check David Brown <david.brown@hesbynett.no> - 2017-01-02 14:28 +0100
      Re: guidelines for pointer check Noob <root@127.0.0.1> - 2017-01-02 17:35 +0100
        Re: Using == operator Noob <root@127.0.0.1> - 2017-01-02 19:03 +0100
          Re: Using == operator David Brown <david.brown@hesbynett.no> - 2017-01-02 23:41 +0100
            Re: Using == operator Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-02 14:54 -0800
              Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-02 15:57 -0800
                Re: Using == operator Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-01-03 16:31 -0500
                Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 14:06 -0800
                Re: Using == operator Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-03 14:44 -0800
                Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 15:05 -0800
                Re: Using == operator Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:42 +0000
                Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 11:46 -0800
                Re: Using == operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-01-03 21:22 -0700
                Re: Using == operator supercat@casperkitty.com - 2017-01-03 15:23 -0800
                Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 15:30 -0800
                Re: Using == operator supercat@casperkitty.com - 2017-01-03 16:02 -0800
                Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 16:30 -0800
                Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 11:26 -0800
                Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-04 09:55 +0000
                Re: Using == operator Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:49 +0000
                Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-10 01:28 +0000
                Re: Using == operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-01-09 19:12 -0700
                Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 09:12 -0800
                Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 09:54 -0800
              Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-03 21:08 +0000
                Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 06:44 -0800
  Re: guidelines for pointer check Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2017-01-04 08:54 -0800
    Re: guidelines for pointer check Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-14 00:51 -0800

csiph-web