problems with pointers

I have problem with solving pointers.
I a redesigning a function. In main() I have:

struct jpeg_decompress_struct cinfo;

Then the function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
bool JPEG_prepareInfo(char * filename, struct jpeg_decompress_struct* cDecompresInfo)
{
  struct my_error_mgr jerr;
  FILE * infile;                // source file

  if ((infile = fopen(filename, "rb")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    return false;
    }

  /** 1) allocate & initialize JPEG decompression object */
  *cDecompresInfo.err = jpeg_std_error(&jerr.pub);
  jerr.pub.error_exit = my_error_exit;
  if (setjmp(jerr.setjmp_buffer)) {
    jpeg_destroy_decompress(&cinfo);
    // fclose(infile); // close the input file and return
    return 0;
  }
  jpeg_create_decompress(&cinfo);

  /** 2) specify data source (eg, a file) */
  jpeg_stdio_src(&cinfo, infile);

  /** 3) read file parameters with jpeg_read_header() */
  (void) jpeg_read_header(&cinfo, TRUE);

    return true;
}


After call:
isOpen = JPEG_prepareInfo(filename, &cinfo);

I god errors like that:
request for member 'err' in something not a structure or union|

The original code was:
1
2
jpeg_decompress_struct cinfo
cinfo.err = jpeg_std_error(&jerr.pub);



There is one more part in different functon, having same type struct jpeg_decompress_struct* cDecompresInfo which I don't know how to change - original code:
1
2
rows_buffer = (*cinfo.mem->alloc_sarray)
                ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride_len, 1);



Can you help to correct the pointers?
Last edited on
Line 12:

*cDecompresInfo.err

Remember that the dot operator (.) has a higher precedence than the dereference operator (*). So this line is trying to dereference 'err', not your cDecompresInfo pointer.

Instead, if you want to access a member via a pointer, it's typical to use the arrow operator (->) instead of the dot operator:

 
cDecompresInfo->err
Oh man, this is what I tried already but it tells me:
error: incompatible types when assigning to type 'struct jpeg_error_mgr' from type 'struct jpeg_error_mgr *'|

I can try this:
1
2
3
4
5
(*cDecompresInfo).err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
  if (setjmp(jerr.setjmp_buffer)) {
    jpeg_destroy_decompress(&cinfo); // LINE 41 - &cinfo not changed yet
  ...


The line 41 yet need change

Should I type:
&*cDecompresInfo or &DecompresInfo ? I try first one and error disapears

Last error:
1
2
GLOBAL(int)
int read_JPEG_file_rgb2hsv(unsigned char ** image_buffer, struct jpeg_decompress_struct* cDecompresInfo)

two or more data types in declaration specifiers|

Solved:
Wanted to remove GLOBAL(int)
Last edited on
Last line which is crashing:
(void) jpeg_finish_decompress(&*cDecompresInfo); // Finish decompression, no errors possible how to correct?
http://paste.ofcode.org/jC5TXVGqKJVDeu9xwr3nTr
Topic archived. No new replies allowed.