A
A
Alexey Denisov2021-08-29 12:52:20
C++ / C#
Alexey Denisov, 2021-08-29 12:52:20

How to run C code in C++ project?

Please tell me, there is a source code - which is successfully compiled in a project under C.
I copy this code to a project under C ++, errors like this immediately appear:

cannot convert 'char*' to 'int*' for argument '1' to 'int
invalid conversion from 'int*' to 'int'

And a bunch more Warnings
warning: narrowing conversion of '143' from 'int' to 'char' inside

The C program runs successfully.
How can you ignore this, because it is ignored in C, or does it depend on the settings of the Compiler, or rather its versions?
Otherwise, I can’t rewrite the code, apparently I don’t have enough experience.
(there is an array of HEX bytes - char[], then this array is passed to the function by reference - which takes int and then processes these bytes (Copy-paste function from the IdaPro Disassembler) )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2021-08-29
@Mercury13

cannot convert 'char*' to 'int*' for argument '1' to 'int

Usually a mistake. The function wanted a pointer to 4-byte words - and we pass it a pointer to bytes.
If you really need to consider int* as char* (for example, we are not working with data of a certain type, but simply with bytes in memory) - use reinterpret_cast.
invalid conversion from 'int*' to 'int'

Almost always a mistake. The function wanted a number - and we pass it a pointer.
If for some reason you really need to perceive the pointer value as a number, use reinterpret_cast.
Another option is also possible - you simply missed the “dereference” * operation.
warning: narrowing conversion of '143' from 'int' to 'char' inside

Exactly an error - 143 does not fit into char (-128 ... 127). If you really need it, use static_cast.
Show me the code, and I'll arrange a revision for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question