Incompatible pointer type

5 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 1 month 3 days ago
Joined: 2014-04-21 21:15
Incompatible pointer type
  1. CFLAGS = $(INCPATH) -Wall -Werror -Wwrite-strings -Wextra -Wno-unused-parameter -D__AMIGADATE__=\"`c:date LFORMAT %Y-%m-%d`\" -O3
  2.  
  3. struct JPEGDecHandle *jph;
  4.  
  5. err=IJpeg->AllocJPEGDecompress(&jph,
  6. JPG_SrcMemStream, jstream,
  7. JPG_SrcMemStreamSize, jstreamsize,
  8. TAG_DONE);
I am trying to compile the jpeg_lib.lha (Aminet) library example 'save_file'. I can't get past this error: warning: passing argument 2 of 'IJpeg->AllocJPEGDecompress' from incompatible pointer type. It happens for all of these functions:
  1. AllocJPEGDecompress
  2. AllocBufferFromJPEG
  3. DecompressJPEG
  4. AllocJPEGCompress
  5. CompressJPEG
  6. FreeJPEGCompress
  7. FreeJPEGDecompress
I have tried every variation of cast I can think of. Tried -fno-strict-aliasing (like in jabirulo's post). Same thing every time.
jabirulo
jabirulo's picture
Offline
Last seen: 4 days 21 hours ago
Joined: 2013-05-30 00:53
Re: Incompatible pointer type
Tried the jpeg's loadfile source code and I get the same warning:
  1. struct JPEGDecHandle *jph;
  2. ...
  3. mainGFX.c:191:25: warning: passing argument 2 of 'IJpeg->FreeJPEGDecompress' from incompatible pointer type [-Wincompatible-pointer-types]
  4. IJpeg->FreeJPEGDecompress( jph );
  5. ^
  6. mainGFX.c:191:25: note: expected 'struct JPEGDecHandle *' but argument is of type 'struct JPEGDecHandle *'
  7.  
  8. #
even doing "IJpeg->FreeJPEGDecompress( (struct JPEGDecHandle *)jph );" I get the same warning
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
salass00
salass00's picture
Online
Last seen: 13 min 52 sec ago
Joined: 2011-02-03 11:27
Re: Incompatible pointer type
The problem is that the include file "interfaces/jpeg.h" doesn't include "jpeg/jpeg.h", so when gcc first encounters struct JPEGDecHandle in a function definition there it creates an implicit local definition. That's why later when it encounters the JPEGDecHandle in "jpeg/jpeg.h" it thinks it's a different structure. This is also why you should always check the first warning/error first when compiling C code because it will often explain later ones and when you fix it they will be fixed too. In this case gcc reported this error:
  1. In file included from ../../include/proto/jpeg.h:31:0,
  2. from main.c:20:
  3. ../../include/interfaces/jpeg.h:28:71: error:struct JPEGDecHandle’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
  4. LONG APICALL (*AllocJPEGDecompressA)(struct JpegIFace *Self, struct JPEGDecHandle ** jph, struct TagItem * taglist);
Fix this either by moving the "#include <jpeg/jpeg.h>" line before "#include <proto/jpeg.h>", or by adding "#include <jpeg/jpeg.h>" just after:
  1. #ifndef EXEC_TYPES_H
  2. #include <exec/types.h>
  3. #endif
  4. #ifndef EXEC_EXEC_H
  5. #include <exec/exec.h>
  6. #endif
  7. #ifndef EXEC_INTERFACES_H
  8. #include <exec/interfaces.h>
  9. #endif
in "interfaces/jpeg.h".
jabirulo
jabirulo's picture
Offline
Last seen: 4 days 21 hours ago
Joined: 2013-05-30 00:53
Re: Incompatible pointer type

Added "#include <jpeg/jpeg.h>" in interfaces/jpeg.h and no more warnings. THXALOT

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
mritter0
mritter0's picture
Offline
Last seen: 1 month 3 days ago
Joined: 2014-04-21 21:15
Re: Incompatible pointer type
I was loading the proto first, flipped the order and it compiled. No need to manually add the line to interfaces. Thank you!
Log in or register to post comments