assignment discards qualifiers from pointer target type

This is a discussion on assignment discards qualifiers from pointer target type within the C Programming forums, part of the General Programming Boards category; I'm getting this warning from GCC and don't really understand the problem. The code works as intended, but I'd like ...

  1. #1
    not-a-geek
    Join Date
    Apr 2004
    Posts
    210

    Question assignment discards qualifiers from pointer target type

    I'm getting this warning from GCC and don't really understand the problem. The code works as intended, but I'd like to get rid of the warning (without suppressing it).

    The code XORs a buffer against a MD5 hash. The warning refers to the red line:

    Code:
    /* requires buffersizes multiples of 4 and MD5_LEN to be 16 */
     void Xorize4(int *piFromTo, const int *piHash, int iLen) {
       //int MD5DIVI= MD5_LEN / sizeof(int);
       int *piHashEnd;
       piHashEnd= piHash +4;
       int *piStart= piFromTo;
       int *piEnd= piFromTo +iLen;
      
       while (piHash < piHashEnd) {
     	while (piFromTo < piEnd) {
     	  *piFromTo^= *piHash;
     	  piFromTo+= 4;
     	}
       
     	piHash++;
     	piFromTo= ++piStart;
       }
     }
    Any ideas?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    So make
    Code:
    const int *piHashEnd;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You're subverting the type system by trying to use a non-const pointer to alias a const pointer. Make piHashEnd const as well.
    My best code is written with the delete key.

  4. #4
    not-a-geek
    Join Date
    Apr 2004
    Posts
    210
    Quote Originally Posted by Salem
    So make
    Code:
      const int *piHashEnd;
    Wow, that was fast. Thank you Salem, this works.

    edit: and Prelude also
    Last edited by Nyda; 06-19-2004 at 10:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. c program error
    By cutelucks in forum C Programming
    Replies: 14
    Last Post: 12-21-2007, 10:12 PM
  3. warning: assignment from a incompatible pointer type
    By enderandrew in forum C Programming
    Replies: 8
    Last Post: 09-22-2007, 04:07 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Discards qualifier from pointer target type?
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-16-2002, 02:12 PM

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