3 Replies - 1350 Views - Last Post: 12 October 2012 - 11:43 PM Rate Topic: -----

#1 fyrddin  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 17-August 12

invalid conversion from ‘char*’ to ‘png_byte*’

Posted 11 October 2012 - 11:36 PM

I'm n00b to using g++ command line compiler. Compiles file with gcc.
The error points to the second "if" statement.

bool load_png(char* file_name, png_type* png_type_pointer)
{  
  char header[8];
  FILE* png_file = fopen(file_name, "rb");
  if (png_file == NULL)
  { 
    printf("Cannot open file %s\n", png_file);
    return false;
  }
  
  char png_header[8]; // maximum header size
  fread(png_header, 1, 8, png_file);
  if (png_sig_cmp(png_header, 0, 8))
  {
    printf("File %s not recognized as png\n", file_name);
    return false;
  }


Cheers,

Shawn

Is This A Good Question/Topic? 1
  • +

Replies To: invalid conversion from ‘char*’ to ‘png_byte*’

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1770
  • View blog
  • Posts: 3,429
  • Joined: 30-May 10

Re: invalid conversion from ‘char*’ to ‘png_byte*’

Posted 11 October 2012 - 11:46 PM

> I'm n00b to using g++ command line compiler. Compiles file with gcc.
So why do you want to compile C code with a C++ compiler?
Was This Post Helpful? 0
  • +
  • -

#3 fyrddin  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Re: invalid conversion from ‘char*’ to ‘png_byte*’

Posted 12 October 2012 - 12:06 AM

View PostSalem_c, on 12 October 2012 - 06:46 PM, said:

> I'm n00b to using g++ command line compiler. Compiles file with gcc.
So why do you want to compile C code with a C++ compiler?

Just been converting what needs to be so I can use classes.
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1770
  • View blog
  • Posts: 3,429
  • Joined: 30-May 10

Re: invalid conversion from ‘char*’ to ‘png_byte*’

Posted 12 October 2012 - 11:43 PM

Imagine what you would do if you didn't have access to the PNG 'C' code, and all you had was a header file and a library.

// probably in a header file
extern "C" {
bool load_png(char* file_name, png_type* png_type_pointer);
}
// a wrapper class
class myPNG {
  private:
    png_type handle;
  public:
    bool load ( string filename ) {
        // copy the filename to a writeable array, since
        // the API didn't mark it as const (so don't trust it)
        char *temp = new char[filename.length()+1];
        strcpy(temp,filename.c_str());
        bool result = load_png(temp,&handle);
        delete [] temp;
        return result;
    }
};


That is, you write a small wrapper class around the 'C' code which presents the rest of your application with a C++ interface.

In your code, you now do
myPNG image;
image.load("picture.png");

and you're up and running.

Even if you do have the source code (say it's a free library like libpng), you don't want the hassle of combing through the code making it compatible with your C++ compiler, every time the library gets updated.

Getting C code to compile as C++ code is more work than just throwing in a few casts to make the compiler STFU.
http://en.wikipedia....f_C_and_C%2B%2B
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1