Thread: another vector question

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    LPCVOID is a typedef, not a #define. And it doesn't have anything to do with templates. Win32 is a C interface, and templates are C++, not C.

  2. #17
    Banned
    Join Date
    Nov 2007
    Posts
    678
    i am not saying anything like you have assumed from my post

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Oh. Then could you clarify?

  4. #19
    Banned
    Join Date
    Nov 2007
    Posts
    678
    consider this:
    why we should use LPCVOID instead of const void *?

  5. #20
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    For type-matching with an API that specifies the use of such type.

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manav View Post
    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
    Not really. You need some more practice, that's all. It removes long, template-ish lines which has to be duplicated all the time.

    but anyways such typedefs have advantages:
    like:
    Code:
    char* p, q r; // not all are pointers :(
    LPSTR p, q, r; // all are pointers :)
    Code:
    typedef LPVOID void*;
    typedef LPPVOID void**;
    typedef LPINT int*;
    
    void myfunc(LPVOID p);
    
    int main()
    {
        LPVOID myvar;
        LPPVOID myvarr;
        myvarr = &myvar; /* Wtf? How can you assign the address of one variable to another which is not a pointer? */
        int myint = 0;
        LPINT myint2;
        myint2 = &myint; /* Wtf? How can you assign the address of one variable to another which is not a pointer? */
        *myint2 = 5; /* Wtf? Myint2 is a variable, not a pointer */
    
        LPVOID myvar2 = 100; /* Valid in C! */
        myfunc(myvar2, 4);
    }
    
    void myfunc(LPVOID p)
    {
        int val = 4;
        memcpy(p, &val, sizeof(val));
    }
    It could go on. This will make your head hurt in complex code whereas, if you simply typed int, int*, void* or void**, it would be so much simpler.
    Worse is if someone renames them such as:

    Code:
    typedef struct
    {
        /* ... */
    } *mystruct;
    /* Wtf? mystruct is a pointer, not a variable! */
    Quote Originally Posted by robwhit View Post
    For type-matching with an API that specifies the use of such type.
    Use documentation instead. It's much less error prone than using stupid typedefs for taking arguments.
    Say: this function expects the address of a variable of type X instead of typing LPVOID.
    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. #22
    Banned
    Join Date
    Nov 2007
    Posts
    678
    For type-matching with an API that specifies the use of such type.
    Well in this case ...
    It would have been much better if the API used this:
    Code:
    void MSAPIFunction(char * s);
    instead of this ugliness:
    Code:
    typedef char * LPSTR;
    void MSAPIFunction(LPSTR s);

  8. #23
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    myvarr = &myvar; /* Wtf? How can you assign the address of one variable to another which is not a pointer? */
    Smart pointers aren't pointers either. Spotting that a type name starts with P or LP isn't really harder than spotting a * in the declaration. It's a very simple convention.

    Not saying that I'd use it, but I don't see it decreasing readability.
    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

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It introduces confusion if abused. There have been examples of that with linked lists in the C forum multiple times.
    At least it boggles my mind.
    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.

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Win32 is an API, not an implementation. There might be another implementation on another platform which has different representations for variable types. Then what would you do if you wanted binary compatibility?

    I think a better solution would be to have an API compatibility layer between the Win32 API and the code that you need to be in regular C types. Also consider whether you actually need Win32 types or C data types. I don't think Win32 data types would be a good choice for a linked list. Where's the connection?
    Quote Originally Posted by Elysia View Post
    Use documentation instead.
    I thought I was...?
    Quote Originally Posted by Elysia View Post
    It introduces confusion if abused.
    Not a good mantra for computer programming.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Of course it's fine to typedef types.
    But it's bad to typedef pointers to types.
    :|
    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.

  12. #27
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Ah I see. But pointers are types. How do you know that the pointer types are the same?

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    typedef something mytype;
    void foo(mytype* p);

    This guarantees that it takes a pointer to something of type mytype.
    So why the need for pointer typedefs?
    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. #29
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Just as a quick clarification to Elysia, The only reason I even used LPCVOID was because he used LPVOID. Had he not used a win32 type I would have also not used a win32 type. Furthermore, I try to always match JAVA source with JAVA source, C++ source with C++ source, and even pseudo-code with pseudo-code. It represents one of two things happening, people getting an understandable answer to their question, or people wondering "why on earth did he post pseudo-code as an answer?" Thus inspiring them not to post it in the question

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I see. Well, don't worry - I'm not blaming anyone (phew).
    Friends again?
    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.

Popular pages Recent additions subscribe to a feed