Discards qualifier from pointer target type?

This is a discussion on Discards qualifier from pointer target type? within the C Programming forums, part of the General Programming Boards category; I have a function which is declared as the following Code: void errorParser(int error,char* dir) When I try to call ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    87

    Discards qualifier from pointer target type?

    I have a function which is declared as the following

    Code:
    void errorParser(int error,char* dir)
    When I try to call it as follows

    Code:
    errorParser(errno,(const char*)getenv("HOME"));
    I get the following error:

    passing arg 2 of 'errorParser' discards qualifier from pointer target type?

    What does that mean? And should I be worried about it?????
    PuterPaul.co.uk - Portfolio site

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > What does that mean?
    Means what it says

    The parameter in the function prototype is
    char *

    The parameter you are passing is
    const char *

    const is a qualifier, and it's being discarded by the (implicit) cast to make a 'const char *' into a 'char *'

    > And should I be worried about it?
    Perhaps

    Does errorParser modify the dir parameter?

    If it does, then you're sunk - who knows what could happen

    If it doesn't, the best fix is to declare
    void errorParser(int error, const char* dir)

    Then it wont matter whether you pass a const char* or a char* to it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Incompatible Pointer Type warnings
    By trillianjedi in forum C Programming
    Replies: 3
    Last Post: 06-11-2008, 04:16 PM
  2. c program error
    By cutelucks in forum C Programming
    Replies: 14
    Last Post: 12-21-2007, 10:12 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21