untrunc icon indicating copy to clipboard operation
untrunc copied to clipboard

error: incompatible types in assignment

Open sunnybear opened this issue 4 years ago • 3 comments

atom.cpp: In constructor ‘Atom::Atom()’: atom.cpp:104:67: error: incompatible types in assignment of ‘const char [1]’ to ‘char [5]’ Atom::Atom() : start(0), length(0), name(""), head(""), version("") { } ^ atom.cpp:104:67: error: incompatible types in assignment of ‘const char [1]’ to ‘char [4]’ atom.cpp:104:67: error: incompatible types in assignment of ‘const char [1]’ to ‘char [4]’

After fixing this - a lot of new errors. System CentOS Linux release 7.5.1804 (Core), g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

sunnybear avatar Oct 25 '20 21:10 sunnybear

try https://github.com/anthwlock/untrunc#centos-7

anthwlock avatar Oct 26 '20 18:10 anthwlock

In atom.cpp

// Atom                                                                                                                                                                                   
Atom::Atom() : start(0), content_start(0), length(0), name(""), head(""), version("") { }

in atom.h

class Atom {
public:
    int64_t start;       //including 8 header bytes                                                                                                                                   
    int64_t content_start; //after the name and eventually the extended 64 bit size;                                                                                                  
    int64_t length;      //including 8 header bytes                                                                                                                                       
    char    name[5];
    char    head[4];
    char    version[4];

compiler output

atom.cpp: In constructor ‘Atom::Atom()’:
atom.cpp:105:85: error: incompatible types in assignment of ‘const char [1]’ to ‘char [5]’
 Atom::Atom() : start(0), content_start(0), length(0), name(""), head(""), version("") { }
                                                                                     ^
atom.cpp:105:85: error: incompatible types in assignment of ‘const char [1]’ to ‘char [4]’
atom.cpp:105:85: error: incompatible types in assignment of ‘const char [1]’ to ‘char [4]’

The code is trying to put "" (A.K.A const char [1]) into name[5] (A.K.A char[5]) and so on for the "" constructor arguments.

How did this code ever compile? Why didn't you use std::string?

ambiamber avatar Sep 19 '22 00:09 ambiamber

Hi, I did not use std::string because the mov format has a fixed name length of 4 chars (I added the 5th to zeroend the name a conveniently printf it). The code compiles and work in gcc (there isn't even a warning), I had a look at the C++11 standards and it seems that initializing a char array like this

    char name[5] = "";
    

is legal: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf page 207.

Maybe initialization in the constructor is different on your compiler (which?)? Maybe C++11 is not enabled?

Anyway, I moved the initialization in the class.

ponchio avatar Sep 19 '22 12:09 ponchio