Results 1 to 3 of 3

Thread: coding style

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default coding style

    Hello,
    I read a bit thinking in C++ and other book and I see that for declare pointer the style more used is int* y; then I read the Ansi C Ritchie's book and I say it use int *y; what the best tyle?
    Actually, it seems better the second; for example: "int *y, *z" should be ok but not "int* y, z" (this last it's not the same). I read the '*' is referer to name variabile and not the type.
    What do you think?
    Regards

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: coding style

    Actually it doesn't matter when you are declaring only one pointer variable. (which is why bruce probably didn't bother to use the latter version)

    When you are declaring multiple pointer variables in a single declarations then
    int *x, *y; is better since it conveys the meaning more precisely and also hammers the fact that int* is not carried to all variables after the first one.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: coding style

    Making many variable declarations in one line is less readable and error-prone, especially if you use pointers and references with reference symbol next to the type, which is common in C++ sources, as you already noticed.

    You can read moderately popular C++ Programming Style Guidelines by Geotechnical Software Services.
    51th recommendation says:
    The pointer-ness or reference-ness of a variable is a property of the type rather than the name.
    I think that above approach is right and I follow it when writting in C++, but not in C.

Similar Threads

  1. Qt 4.3 Style sheet, new features
    By Angelo Moriconi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2007, 16:22
  2. Qt specific questions regaring coding style
    By Raistlin in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2007, 10:14
  3. Coding style about pointer
    By vql in forum General Programming
    Replies: 4
    Last Post: 5th February 2007, 09:07
  4. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 14:34
  5. What is your coding style ??
    By guestgulkan in forum General Discussion
    Replies: 9
    Last Post: 29th May 2006, 10:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.