Search code examples
c++chartype-conversionuint8t

argument of type uint8_t is incompatible with parameter of type char*


I've been getting the title error recently and I'm not quite sure what I'm doing wrong, anyone have any ideas? relevant code below

Rom.h

//Rom.h
#pragma once
#include <fstream>
struct ROM {
  uint8_t* memblock;
  std::fstream rom;
  std::streampos size;
  int flag;

  void ROM::LoadROM(std::string path, int flag);
  void ROM::BinaryDump(std::string path, std::streampos size);
}

Rom.cpp

//Rom.cpp
#include <iostream>
#include "Rom.h"

void ROM::LoadROM(std::string path, int flag) {
  this->rom.open(path, std::ios::in | std::ios::binary | std::ios::ate);

  if (rom.is_open()) {
    this->size = rom.tellg();
    std::cout << "\nThe Rom is " << rom.tellg() << " byte(s) long." << std::endl;
    this->memblock = new uint8_t[(unsigned int)this->size];
    std::cout << rom.tellg() << " Bytes of memory have been allocated" << std::endl;
    rom.seekg(0, std::ios::beg);
    rom.read(this->memblock, (unsigned int)this->size);
    std::cout << "The contents of the file are stored in memory" << std::endl;
    rom.close();
    if (flag == 0) {
    }
    else {
        BinaryDump(path, this->size);
    }
  }
}

void ROM::BinaryDump(std::string path, std::streampos size) {
  std::fstream binDump(path, std::ios::out | std::ios::binary);

  binDump.write(this->memblock, size);
  delete[] this->memblock;
  binDump.close();
  std::cout << "The ROM has been dumped" << std::endl;
}

Sorry if this is completely obvious but I feel lost here.


Solution

  • uint8_t and char are different types. (Well - this is system dependent, but on your system they are different). You cannot use the two names interchangeably.

    Your question did not mention what line gave the error, but if you look that up you will find that you are passing uint8_t * where in fact the function expects char *.

    I guess it would be rom.read . If so then you could fix the problem with:

    rom.read( reinterpret_cast<char *>(memblock), size );
    

    You do not need to use redundant unsigned int casts or this-> prefixes.

    Another possible solution would be to make memblock have type char *.