Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. All in - pointer declaration

All in - pointer declaration

Scheduled Pinned Locked Moved The Lounge
39 Posts 19 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Single Step Debugger
    wrote on last edited by
    #1

    Type *p;

    or

    Type* p;

    or even

    Type * p;

    Me personally, I do whatever is the current company naming conventions.

    There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

    P M R H C 14 Replies Last reply
    0
    • S Single Step Debugger

      Type *p;

      or

      Type* p;

      or even

      Type * p;

      Me personally, I do whatever is the current company naming conventions.

      There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      (Lights his torch.)

      S O 2 Replies Last reply
      0
      • S Single Step Debugger

        Type *p;

        or

        Type* p;

        or even

        Type * p;

        Me personally, I do whatever is the current company naming conventions.

        There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

        M Offline
        M Offline
        Mike Hankey
        wrote on last edited by
        #3

        Have always used this style.

        Type* p;

        PartsBin an Electronics Part Organizer - An updated version available! JaxCoder.com

        R 1 Reply Last reply
        0
        • P PIEBALDconsult

          (Lights his torch.)

          S Offline
          S Offline
          Single Step Debugger
          wrote on last edited by
          #4

          Wow, that was low!(-level language)

          There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

          1 Reply Last reply
          0
          • S Single Step Debugger

            Type *p;

            or

            Type* p;

            or even

            Type * p;

            Me personally, I do whatever is the current company naming conventions.

            There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

            R Offline
            R Offline
            Ron Anders
            wrote on last edited by
            #5

            type *p;

            1 Reply Last reply
            0
            • S Single Step Debugger

              Type *p;

              or

              Type* p;

              or even

              Type * p;

              Me personally, I do whatever is the current company naming conventions.

              There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #6

              I hate the question. The reason being is that the pointer is part of the type intrinsically, and I want to use it that way but C isn't always consistent about it, so it gets weird no matter what you do. Pointer syntax is funky. It just is. There's no amount of style guidelines that will defunk pointers. Ergo, I do whatever the code around me does. Usually I put it with the type but I know I'm hated for that. :laugh:

              To err is human. Fortune favors the monsters.

              0 1 Reply Last reply
              0
              • S Single Step Debugger

                Type *p;

                or

                Type* p;

                or even

                Type * p;

                Me personally, I do whatever is the current company naming conventions.

                There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                Type *p;

                "In testa che avete, Signor di Ceprano?" -- Rigoletto

                J 1 Reply Last reply
                0
                • S Single Step Debugger

                  Type *p;

                  or

                  Type* p;

                  or even

                  Type * p;

                  Me personally, I do whatever is the current company naming conventions.

                  There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                  Greg UtasG Offline
                  Greg UtasG Offline
                  Greg Utas
                  wrote on last edited by
                  #8

                  Type* p;

                  Robust Services Core | Software Techniques for Lemmings | Articles
                  The fox knows many things, but the hedgehog knows one big thing.

                  <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                  <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                  0 1 Reply Last reply
                  0
                  • S Single Step Debugger

                    Type *p;

                    or

                    Type* p;

                    or even

                    Type * p;

                    Me personally, I do whatever is the current company naming conventions.

                    There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                    J Offline
                    J Offline
                    jeron1
                    wrote on last edited by
                    #9

                    Type* p;

                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                    1 Reply Last reply
                    0
                    • S Single Step Debugger

                      Type *p;

                      or

                      Type* p;

                      or even

                      Type * p;

                      Me personally, I do whatever is the current company naming conventions.

                      There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                      K Offline
                      K Offline
                      k5054
                      wrote on last edited by
                      #10

                      type *p;

                      Because

                      type* p, q

                      doesn't do what it looks like it does. Of course, that kicks off the argument about multiple variables per type declaration.

                      Keep Calm and Carry On

                      D 1 Reply Last reply
                      0
                      • S Single Step Debugger

                        Type *p;

                        or

                        Type* p;

                        or even

                        Type * p;

                        Me personally, I do whatever is the current company naming conventions.

                        There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                        0 Offline
                        0 Offline
                        0x01AA
                        wrote on last edited by
                        #11

                        I prefer Type* p; And this only because my compiler gives a wrning when I don't use a parameter in a method: void Method(char x, char* y) To get rid of the warning I need to do e.g.this void Method(char x, char* /*y*/) On the other hand if I would do something like this (what I'm not doing ...) const char *a= "a", *b= "b"; Then I get angry because the language itself is not what I would name 'consistent' :laugh:

                        1 Reply Last reply
                        0
                        • S Single Step Debugger

                          Type *p;

                          or

                          Type* p;

                          or even

                          Type * p;

                          Me personally, I do whatever is the current company naming conventions.

                          There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                          M Offline
                          M Offline
                          Mircea Neacsu
                          wrote on last edited by
                          #12

                          type* (pointer is part of type) Now moving on: do you do "west const" or "east const"? Standard C++[^] (surely a lot of people - me included - don't want to do productive work today)

                          Mircea

                          T H 2 Replies Last reply
                          0
                          • M Mircea Neacsu

                            type* (pointer is part of type) Now moving on: do you do "west const" or "east const"? Standard C++[^] (surely a lot of people - me included - don't want to do productive work today)

                            Mircea

                            T Offline
                            T Offline
                            trønderen
                            wrote on last edited by
                            #13

                            If pointer is part of the type, make it! Make a typedef and use that when declaring variables.

                            type* x, y;

                            - is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to

                            type y, *x;

                            - is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.

                            M H 2 Replies Last reply
                            0
                            • T trønderen

                              If pointer is part of the type, make it! Make a typedef and use that when declaring variables.

                              type* x, y;

                              - is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to

                              type y, *x;

                              - is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.

                              M Offline
                              M Offline
                              Mircea Neacsu
                              wrote on last edited by
                              #14

                              trønderen wrote:

                              Make a typedef and use that when declaring variables.

                              Amen! Edit: This is one of the (many) early failings of "C". When I write "C" I try to avoid mixing pointer to type and type declarations on the same line and try to keep pointer declarations on their own line. When I do "C++" I'm mostly using stuff like

                              std::unique_ptr a, b;

                              If I see two naked pointers in the same declaration, that is most likely a code smell.

                              Mircea

                              1 Reply Last reply
                              0
                              • H honey the codewitch

                                I hate the question. The reason being is that the pointer is part of the type intrinsically, and I want to use it that way but C isn't always consistent about it, so it gets weird no matter what you do. Pointer syntax is funky. It just is. There's no amount of style guidelines that will defunk pointers. Ergo, I do whatever the code around me does. Usually I put it with the type but I know I'm hated for that. :laugh:

                                To err is human. Fortune favors the monsters.

                                0 Offline
                                0 Offline
                                0x01AA
                                wrote on last edited by
                                #15

                                I agree, see my comment below, I think similar mis feelings. Either way, I'm not worrying about such details. It is what it is and I close both eyes and go through it :laugh:

                                1 Reply Last reply
                                0
                                • T trønderen

                                  If pointer is part of the type, make it! Make a typedef and use that when declaring variables.

                                  type* x, y;

                                  - is y of a pointer type? You know that it isn't. Lots of problems have been caused by making it appear as if x and y have the same type. (Thankfully, the compiler will catch most such wrongful assumptions.) If you change it to

                                  type y, *x;

                                  - is now the type definition for variable x split into two parts, separated by a variable declaration? If you make a typedef, you have a clear, all-in-one-place type definition, not cluttered up by variables. And you would avoid the risk of someone assuming, in the first example, that x and y are of the same type.

                                  H Offline
                                  H Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #16

                                  I generally agree with you, but I am not all in on that agreement, if that makes sense. Here's why: You have to look up a typedef to know what it is, and typedefs everywhere make it harder to know what's going on until you can adopt the fundamental lexicon that your typedefs essentially create. That said, everything you wrote is valid. I just think there are places where it might be overkill.

                                  To err is human. Fortune favors the monsters.

                                  T D 2 Replies Last reply
                                  0
                                  • C CPallini

                                    Type *p;

                                    "In testa che avete, Signor di Ceprano?" -- Rigoletto

                                    J Offline
                                    J Offline
                                    jmaida
                                    wrote on last edited by
                                    #17

                                    I use C and try to be consistent Type *p; example typedef struct { char form[LINE_SIZE]; // command form */ int narg; // number of arguments */ char error; // error code */ } LANG; LANG *LP;

                                    "A little time, a little trouble, your better day" Badfinger

                                    1 Reply Last reply
                                    0
                                    • Greg UtasG Greg Utas

                                      Type* p;

                                      Robust Services Core | Software Techniques for Lemmings | Articles
                                      The fox knows many things, but the hedgehog knows one big thing.

                                      0 Offline
                                      0 Offline
                                      0x01AA
                                      wrote on last edited by
                                      #18

                                      I agree, but as mentioned in my post below... a thing I don't do but is very common:

                                      const char
                                      *a= "a",
                                      *b= "b";

                                      tells us, in this case we are something wrong... :(

                                      Greg UtasG 1 Reply Last reply
                                      0
                                      • 0 0x01AA

                                        I agree, but as mentioned in my post below... a thing I don't do but is very common:

                                        const char
                                        *a= "a",
                                        *b= "b";

                                        tells us, in this case we are something wrong... :(

                                        Greg UtasG Offline
                                        Greg UtasG Offline
                                        Greg Utas
                                        wrote on last edited by
                                        #19

                                        This doesn't bother me, because I never do this kind of thing.

                                        Robust Services Core | Software Techniques for Lemmings | Articles
                                        The fox knows many things, but the hedgehog knows one big thing.

                                        <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                        <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                        1 Reply Last reply
                                        0
                                        • M Mike Hankey

                                          Have always used this style.

                                          Type* p;

                                          PartsBin an Electronics Part Organizer - An updated version available! JaxCoder.com

                                          R Offline
                                          R Offline
                                          Ravi Bhavnani
                                          wrote on last edited by
                                          #20

                                          Me too. Although since I no longer develop in C++, I use:

                                          MyType p;

                                          :) /ravi

                                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups