Thread: another vector question

  1. #1
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    another vector question

    ok, now I need to get an actual pointer to the data in a vector, I have to pass this to a function that only accepts raw pointers.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by abachler View Post
    ok, now I need to get an actual pointer to the data in a vector, I have to pass this to a function that only accepts raw pointers.
    Code:
    &vec[0]

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    so if I have -

    Code:
    string Foo;
    I can just pass

    Code:
    MyFunction((LPVOID)&Foo);
    and that will point to the characters int eh string themselves?

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Not even remotely...

    Example:
    Code:
    MyFunction((LPCVOID)Foo.c_str());

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It seems that string (currently) doesn't really allow non-constant access to the internal buffer (it is not required to be contiguous). You can use a vector<char> instead of string.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Pointers needn't be cast to void* in either C or C++ either.
    Also there's no such thing as LPCVOID
    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.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The only reason I put the cast was to assure that the OP was aware of the fact that std::string::c_str() is constant. Hence the LPCVOID.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is no such thing as LPCVOID. I think it's just better to write const void*.
    All those LP* defines/typedefs are evil anyway. They obfuscate code, makes it harder to read and more prone to errors.
    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.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Whether you like them or not, to say that they don't exist is absurd, and totally irrelevant to the thread, too.
    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

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I said "LPCVOID" didn't exist. Unless you typedef that one yourself, it doesn't exist in any common windows header.
    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.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    OK, you're right. Sorry.
    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

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    I said "LPCVOID" didn't exist. Unless you typedef that one yourself, it doesn't exist in any common windows header.
    http://msdn2.microsoft.com/en-us/library/aa383751(VS.85).aspx

    WinDef.h

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    News to me. Never seen it before that I can remember.
    But... I stand corrected.
    Although, const void* is much easier to read and interpret rather than LPCVOID. I still stand fast to that.
    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.

  14. #14
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And I grepped the wrong directory in my search.
    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. #15
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Elysia View Post
    News to me. Never seen it before that I can remember.
    But... I stand corrected.
    Although, const void* is much easier to read and interpret rather than LPCVOID. I still stand fast to that.
    i am hearing such comments from someone who uses cryptic (to me, at least ) #defines to make it even more difficult to understand template ridden code

    but anyways such typedefs have advantages:
    like:
    Code:
    char* p, q r; // not all are pointers :(
    LPSTR p, q, r; // all are pointers :)

Popular pages Recent additions subscribe to a feed