Thread: silence warning when assigning pointers

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    silence warning when assigning pointers

    Although my code works, I'm getting a warning I don't know how to supress.

    I'm assigning a multi dimensional array of type CHAR** to one of type LPCTSTR*

    I assumed this was ok as all pointers are 32bit in Windows.

    Here is the code causing me problems

    Code:
    BOOL Start(INT ArgCount, TCHAR **Args)
    {
        SC_HANDLE hSc;
        LPCTSTR ServiceName = *Args++;
        LPCTSTR *ServiceArgs = Args;  // error relates to this line
    
    ...
    warning: initialization from incompatible pointer type
    How do I correct this?

    Thanks.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by eth0
    How do I correct this?
    Use a compatible pointer type.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    I can't, it needs to be converted somewhere along the line.


    The TCHAR traces back to a return from one function, and it needs to be used in another as LPCTSTR.

    This must be a failry common occurance.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    This must be a failry common occurance.
    Only in Windows where Microsoft bastardizes everything including C.

    Anyway, have you tried typecasting?
    Code:
    LPCTSTR *ServiceArgs = (LPCTSTR *)Args;
    That should supress the error without making the whole situation any more "correct".
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by itsme86
    Anyway, have you tried typecasting?
    Code:
    LPCTSTR *ServiceArgs = (LPCTSTR *)Args;
    Doh, I was casting with
    Code:
    LPCTSTR *ServiceArgs = (LPCTSTR)Args;
    forgetting it was a MD pointer.

    Stupid mistake.

    Thanks.
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    That's really bad when you're using that hungarian notation thing which was invented to avoid such blunders
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to compile projects ?
    By manzoor in forum C++ Programming
    Replies: 31
    Last Post: 10-15-2008, 11:52 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 9
    Last Post: 10-20-2007, 01:05 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM