Thread: assignment discards qualifiers from pointer target type

  1. #1
    Registered User
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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
    Registered User
    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, 11: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