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. Spaces, stars, and pointers

Spaces, stars, and pointers

Scheduled Pinned Locked Moved The Lounge
question
18 Posts 10 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.
  • T Tim Smith

    so what do all of you believe? That you are wrong. :)

    char* data, data2;

    The format implies that both data and data2 are pointers which is totally wrong.

    char *data, data2;

    This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.

    M Offline
    M Offline
    Michael Dunn
    wrote on last edited by
    #6

    Tim Smith wrote: char* data, data2; If you write that expecting data2 to be a char*,then you don't understand the syntax. Putting the * next to the type is still clearer. ;) ;P --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

    N 1 Reply Last reply
    0
    • T Tim Smith

      so what do all of you believe? That you are wrong. :)

      char* data, data2;

      The format implies that both data and data2 are pointers which is totally wrong.

      char *data, data2;

      This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #7

      Very good point Tim. Maybe thats why I liked the other one subconciously :-) Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

      1 Reply Last reply
      0
      • M Michael Dunn

        Tim Smith wrote: char* data, data2; If you write that expecting data2 to be a char*,then you don't understand the syntax. Putting the * next to the type is still clearer. ;) ;P --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #8

        You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

        M H 2 Replies Last reply
        0
        • A Adam Arthur

          Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?

          E Offline
          E Offline
          Ed Dixon
          wrote on last edited by
          #9

          I see it your way as well. Never write the other way. Ed

          1 Reply Last reply
          0
          • N Nish Nishant

            You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #10

            Nish [BusterBoy] wrote: LPTSTR y1,y2; y1 is now a char * and y2 is a char. bzzzt, wrong. Sorry, you don't get to go on to Final Jeopardy. y1 and y2 are both LPTSTR :) --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

            N 1 Reply Last reply
            0
            • M Michael Dunn

              Nish [BusterBoy] wrote: LPTSTR y1,y2; y1 is now a char * and y2 is a char. bzzzt, wrong. Sorry, you don't get to go on to Final Jeopardy. y1 and y2 are both LPTSTR :) --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #11

              how come Mike? I am puzzled I checked through the chain of typedefs and finally decided that an LPTSTR is a char* and nothin else but a char* oh!!!!! you mean the "typedef" does the trick eh???? gosh!!!! My C basics is bad :-( Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

              M 1 Reply Last reply
              0
              • N Nish Nishant

                how come Mike? I am puzzled I checked through the chain of typedefs and finally decided that an LPTSTR is a char* and nothin else but a char* oh!!!!! you mean the "typedef" does the trick eh???? gosh!!!! My C basics is bad :-( Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #12

                Nish [BusterBoy] wrote: you mean the "typedef" does the trick eh???? Yep :) "LPTSTR" becomes a type name, just like "int" or any other built-in type. --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

                N 1 Reply Last reply
                0
                • M Michael Dunn

                  Nish [BusterBoy] wrote: you mean the "typedef" does the trick eh???? Yep :) "LPTSTR" becomes a type name, just like "int" or any other built-in type. --Mike-- My really out-of-date homepage "Why does anyone have a web page? Too much free time... not enough friends... justifying owning a computer." -- Noel Crane on Felicity Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #13

                  Thanks Mike. I think I can use this as an interview question next time we recruit :-) Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                  1 Reply Last reply
                  0
                  • T Tim Smith

                    so what do all of you believe? That you are wrong. :)

                    char* data, data2;

                    The format implies that both data and data2 are pointers which is totally wrong.

                    char *data, data2;

                    This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.

                    R Offline
                    R Offline
                    realJSOP
                    wrote on last edited by
                    #14

                    Of course, any DECENT programmer wouldn't put multiple declarations on a single line anyway... "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      You know what could be really dangerous? say someone does this. LPTSTR y1,y2; y1 is now a char * and y2 is a char. But without the '*' things can be vague,,, Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                      H Offline
                      H Offline
                      Henry Jacobs
                      wrote on last edited by
                      #15

                      :eek: Don‘t do that! Your post startled me. I have on occasion declared LPTSTR y1, y2; After reading your post I started remembering all the code I used like this so I could fix it before it crashed. X| I now truly understand the purpose of typedef. :-O

                      1 Reply Last reply
                      0
                      • A Adam Arthur

                        Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?

                        D Offline
                        D Offline
                        David Wulff
                        wrote on last edited by
                        #16

                        I agree with you. If there was area for confusion like Tim mentioned above, I would simply declare the variable on a new line. ________________ David Wulff http://www.davidwulff.co.uk "I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg

                        1 Reply Last reply
                        0
                        • T Tim Smith

                          so what do all of you believe? That you are wrong. :)

                          char* data, data2;

                          The format implies that both data and data2 are pointers which is totally wrong.

                          char *data, data2;

                          This format implies that data is a pointer while data2 isn't. Of course, this assumes that you define multiple variables per line. Which isn't really a good idea given the ambiguity of the two previous statements. Tim Smith Descartes Systems Sciences, Inc.

                          A Offline
                          A Offline
                          Anders Molin
                          wrote on last edited by
                          #17

                          I totally agree with you :-) - Anders Money talks, but all mine ever says is "Goodbye!"

                          1 Reply Last reply
                          0
                          • A Adam Arthur

                            Personally, I believe this: char* data; is superior to this: char *data; Because char*, or variable*, more easily identifies the fact you are declaring a pointer. Likewise, char *data="hello"; is inferior to char* data = "hello"; Because the spaces more clearly identify that information you're assigning to the variable. Obviously, this is personal taste and cannot be objectively true, so what do all of you believe?

                            C Offline
                            C Offline
                            Christian Graus
                            wrote on last edited by
                            #18

                            I tend to go for char * data; which clearly shows that the * is a seperate entity which modifys the meaning of the former, and aids in defining the latter. Even if I could, I would not say staticconstchar data, so why would I not also space out the * ? The fact that multiple variables on the one line each need the *, if they are pointers, is another reason I would not space them as you have. However, while I can smell a poll coming on ( and if you're reading Chris, I'd prefer a poll on if people use STL and why/why not), it is, as you say, ultimately a matter of choice. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                            Sonork ID 100.10002:MeanManOz

                            I live in Bob's HungOut now

                            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