linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* C coding convention
@ 2005-12-16  2:12 Joel M. Pareja
  2005-12-16  2:16 ` Robert P. J. Day
  0 siblings, 1 reply; 3+ messages in thread
From: Joel M. Pareja @ 2005-12-16  2:12 UTC (permalink / raw)
  To: C programming list

Hi!

I just would like to hear ideas about a convention that my boss is
insisting on being implemented which I personally disagree.

Putting opening/closing brackets for case statements:

  switch (type)
  {
    case 1:
=>  {
      /* do something */
      break;
=>  }

    ....

    default:
    {
      /* do something */
      break;
    }
  }

*I am aware that this is just a very small thing to argue. :-)

If you agree with my boss, could you point to me open source projects
that use this convention.

Thanks.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C coding convention
  2005-12-16  2:12 C coding convention Joel M. Pareja
@ 2005-12-16  2:16 ` Robert P. J. Day
  2005-12-16 10:59   ` Glynn Clements
  0 siblings, 1 reply; 3+ messages in thread
From: Robert P. J. Day @ 2005-12-16  2:16 UTC (permalink / raw)
  To: Joel M. Pareja; +Cc: C programming list

On Fri, 16 Dec 2005, Joel M. Pareja wrote:

> Hi!
>
> I just would like to hear ideas about a convention that my boss is
> insisting on being implemented which I personally disagree.
>
> Putting opening/closing brackets for case statements:
>
>   switch (type)
>   {
>     case 1:
> =>  {
>       /* do something */
>       break;
> =>  }
>
>     ....
>
>     default:
>     {
>       /* do something */
>       break;
>     }
>   }
>

it's a bad idea since it just wastes screen space -- chewing up an
entire line for a single brace.  bad boss.  no biscuit.

rday

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C coding convention
  2005-12-16  2:16 ` Robert P. J. Day
@ 2005-12-16 10:59   ` Glynn Clements
  0 siblings, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2005-12-16 10:59 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Joel M. Pareja, C programming list


Robert P. J. Day wrote:

> > I just would like to hear ideas about a convention that my boss is
> > insisting on being implemented which I personally disagree.
> >
> > Putting opening/closing brackets for case statements:
> >
> >   switch (type)
> >   {
> >     case 1:
> > =>  {
> >       /* do something */
> >       break;
> > =>  }
> >
> >     ....
> >
> >     default:
> >     {
> >       /* do something */
> >       break;
> >     }
> >   }
> >
> 
> it's a bad idea since it just wastes screen space -- chewing up an
> entire line for a single brace.  bad boss.  no biscuit.

It has the advantage of forcing a separate variable scope for each
case. That could conceivably prevent bugs if you're using the C99
feature of declaring variables in the middle of a block, e.g.:

  switch (type)
  {
    case 1:
      int i = 0;
      /* do something */
      break;

    ....

    default:
      int j = 1;
      foo(i); /* oops; meant "j", but the compiler won't complain
		 because "i" is in scope here */
      break;
  }

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-16 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-16  2:12 C coding convention Joel M. Pareja
2005-12-16  2:16 ` Robert P. J. Day
2005-12-16 10:59   ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).