View Poll Results: Where do you put your opening brace?

Voters
53. You may not vote on this poll
  • Style 1 (opening brace on same line)

    18 33.96%
  • Style 2 (opening brace on next line)

    35 66.04%

Curly Brace Placement

This is a discussion on Curly Brace Placement within the General Discussions forums, part of the Community Boards category; Originally Posted by Elysia Sometimes it may be just a "style," but sometimes it may have some meaning behind it. ...

  1. #76
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Elysia View Post
    Sometimes it may be just a "style," but sometimes it may have some meaning behind it.
    I have chosen a particular style mostly because I find it more readable.
    As for the T* vs T * debate, I tended to stick with T* because it's a type and I find * next to the name retarded, because * is NOT part of the name.
    Nowadays, I'm slowly leaning towards the middle ground: T * var for a reason. Mostly because T is the type it points to and * means it's a pointer. Thus I might do T* * var, because var points to a T*.
    So sometimes there is a reason behind our styles
    if * was part of the type then

    Code:
    foo* b, a, r;
    would give you 3 pointers, it IS part of the name
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  2. #77
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> Although, I guess it would be just as easy to use the horizontal scroll bar to move over if it's indented a lot... Maybe that would ........ off the vi people enough to switch to a real IDE.

    Yeah, I use a Scintilla-based IDE and it definitely has issues with horizontal scrolling (read: convulses). What do you use, by the way?



    ITSA
    Socket Library!

  3. #78
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Oh great -- now we're talking about editors!

    Usually KDevelop. Sometimes kate. Occasionally vim.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #79
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by ಠ_ಠ View Post
    if * was part of the type then

    Code:
    foo* b, a, r;
    would give you 3 pointers, it IS part of the name
    Oh yeah. Lucky I never actually started to do this then...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #80
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> would give you 3 pointers, it IS part of the name

    Tomorrow your going to wake up and realize that that doesn't make any sense.

    EDIT:
    >> would give you 3 pointers
    Actually, that probably would have been a good way to implement it, from a language-design standpoint.
    Last edited by Sebastiani; 06-16-2009 at 03:48 PM.



    ITSA
    Socket Library!

  6. #81
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Sebastiani View Post
    >> would give you 3 pointers, it IS part of the name

    Tomorrow your going to wake up and realize that that doesn't make any sense.
    Code:
    foo *b, *a, *r;
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  7. #82
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Sebastiani View Post
    >> would give you 3 pointers, it IS part of the name

    Tomorrow your going to wake up and realize that that doesn't make any sense.
    Sure it does. The only ptr will be the first one. What if you wanted 2, are you supposed to go
    Code:
    char* a, b, * c;
    Why bother with a rule if most of the time you need an "exception"?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #83
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> Sure it does. The only ptr will be the first one. What if you wanted 2, are you supposed to go

    Well, OK. It kind of "straddles the fence" then, I guess. But I still wouldn't consider it part of the name.



    ITSA
    Socket Library!

  9. #84
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Sebastiani View Post
    >> Sure it does. The only ptr will be the first one. What if you wanted 2, are you supposed to go

    Well, OK. It kind of "straddles the fence" then, I guess. But I still wouldn't consider it part of the name.
    I agree, but I think it's more closely related to the name, as I have never used a pointer without dereferencing it at least once
    Last edited by ಠ_ಠ; 06-16-2009 at 04:03 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  10. #85
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Technically speaking, it's part of the declarator. A declgroup is formed of a single declspec, followed by one or more declarator-initializer groups. Everything that binds to the name (pointer, reference, array bounds, function arguments) is part of the declarator, while the bunch of keywords (typedef, friend, const, volatile, auto, static, extern, int, long, short, unsigned, signed, wchar_t, char, bool, float, double, class, struct, union) at the start is the declspec. The declspec combines with each of the declarator-initializer groups to form declarations.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #86
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    >> Technically speaking, it's part of the declarator.

    Well that settles then, I guess.



    ITSA
    Socket Library!

  12. #87
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by ಠ_ಠ View Post
    if * was part of the type then

    Code:
    foo* b, a, r;
    would give you 3 pointers, it IS part of the name
    It is part of the type, because if your example, the type of b is foo*, not foo. Hence, the type of a != the type of b.
    Why they chose to do it this way, I frankly have no idea.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #88
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by Elysia View Post
    It is part of the type, because if your example, the type of b is foo*, not foo. Hence, the type of a != the type of b.
    Why they chose to do it this way, I frankly have no idea.
    Yes, b is a pointer, but a and r are not, that was my point

    the reason they choose to do that is because it's not part of the type, how would you make 3 pointers consistent with your interpretation with *?
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  14. #89
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Being a pointer is part of the type. The * is part of the declarator that makes the declared entity be of pointer type. Or in other words, from a compiler writer's view, types are a property of variables and expressions, not of declarations.

    In yet other words, compiler writers have a slightly different naming convention for code. In this:
    Code:
    int * p;
    most programmers would call "int *" the type. But to me, the only type here is "pointer to int", which is a property of the variable p. "int *" is just a part of the declaration of p.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #90
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    The way I was taught to look at it is this:

    Code:
    int *foo, *bar;
    
    *foo is an int
    *bar is an int
    Kind of like you're declaring the dereferenced foo and bar as ints, from which implicitly follows that they're both of type pointer to int. Before someone explained it to me like this I was switching between the three styles as I couldn't decide which one made the most logical sense to me.

Page 6 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is curly braces here is a must?
    By mashour06 in forum C Programming
    Replies: 8
    Last Post: 04-25-2009, 04:41 PM
  2. Curly brace question
    By kenryuakuma in forum C++ Programming
    Replies: 12
    Last Post: 12-16-2008, 06:06 PM
  3. Placement new?
    By Elysia in forum C++ Programming
    Replies: 9
    Last Post: 02-26-2008, 03:50 AM
  4. My Placement come true
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 06-07-2004, 06:07 AM
  5. CIOS college placement tests
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-13-2002, 01:33 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21