rvddt
rvddt copied to clipboard
C/C++ Data Sizes
In msvc or gcc on windows, data sizes are different from gcc on regular linux platforms.
Particularly, long int
is 4 bytes, and long long int
is 8 bytes.
> make
...
g++ -DDEBUGGING_HACKS -Wall -Werror -std=c++11 -I. -c -o memory.o memory.cc
memory.cc: In member function 'void memory::dump(uint64_t, uint64_t)':
memory.cc:198:26: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Werror=format=]
198 | fprintf(ddtout, " %8.8lx:", addr&~0x0f);
| ~~~~~^ ~~~~~~~~~~
| | |
| | uint64_t {aka long long unsigned int}
| long unsigned int
...
As stated here for windows, linux, and mac:
Suggestion: If it is important to you for integer types to have the same size on all Intel platforms, then consider replacing "long" by either "int" or "long long". The size of the "int" integer type is 4 bytes and the size of the "long long" integer type is 8 bytes for all the above combinations of operating system and architecture.
And if i correctly understand the table from this page, you can replace the modifier l
- long
by ll
- long long
, so the format string would be " %8.8llx:"
, and this will make gcc on windows\linux-x86 happy again.
Yeah. My mistake. This app should have been done using cout & insertion operator.
When I have time I'll have to rewrite it.
There are several other simulators out there if you just one that you can use. I am not sure if there are any interactive ones that are as simplistic as rvddt though. Definitely not when I wrote it.
-John
On 10/16/20 1:07 PM, myCrack wrote:
In msvc or gcc on windows, data sizes are different from gcc on regular linux platforms. Particularly, |long int| is 4 bytes, and |long long int| is 8 bytes.
make ... g++ -DDEBUGGING_HACKS -Wall -Werror -std=c++11 -I. -c -o memory.o memory.cc memory.cc: In member function 'void memory::dump(uint64_t, uint64_t)': memory.cc:198:26: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Werror=format=] 198 | fprintf(ddtout, " %8.8lx:", addr&~0x0f); | ~~~~~^ ~~~~~~~~~~ | | | | | uint64_t {aka long long unsigned int} | long unsigned int ...
As stated here https://software.intel.com/content/www/us/en/develop/articles/size-of-long-integer-type-on-different-architecture-and-os.html for windows, linux, and mac:
*Suggestion*: If it is important to you for integer types to have the same size on all Intel platforms, then consider replacing "long" by either "int" or "long long". The size of the "int" integer type is 4 bytes and the size of the "long long" integer type is 8 bytes for all the above combinations of operating system and architecture.
And if i correctly understand the table from this page https://en.cppreference.com/w/cpp/io/c/fprintf, you can replace the modifier |l| - |long| by |ll| - |long long|, so the format string would be |" %8.8llx:"|, and this will make windows-gcc happy again.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/johnwinans/rvddt/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQ6H766S3Z2XDHB6TEFAGLSLCDUNANCNFSM4STUWNPQ.
FYI - Neither of our solutions were particularly portable. I changed that print line to use inttypes.h for the line of concern. While testing I found & fixed another formatting problem. Now it is working (for me on Linux again) and formats properly.
Here is another three errors:
> g++ -DDEBUGGING_HACKS -Wall -Werror -std=c++11 -I. -c -o memory.o memory.cc
memory.cc: In member function 'void memory::dump(uint64_t, uint64_t)':
memory.cc:199:19: error: unknown conversion type character 'I' in format [-Werror=format=]
199 | fprintf(ddtout, " %8.8" PRIx64 ":%s", addr&~0x0f, startingoffset>8?" ":"");
| ^~~~~~~~~~~~~~~~~~~~
memory.cc:199:19: error: format '%s' expects argument of type 'char*', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'} [-Werror=format=]
memory.cc:199:19: error: too many arguments for format [-Werror=format-extra-args]
And here is the fragment from gcc include file inttypes.h
:
/* 7.8.1 Macros for format specifiers
*
* MS runtime does not yet understand C9x standard "ll"
* length specifier. It appears to treat "ll" as "l".
* The non-standard I64 length specifier causes warning in GCC,
* but understood by MS runtime functions.
*/
#if defined(_UCRT) || __USE_MINGW_ANSI_STDIO
...
#else
...
#define PRIx64 "I64x"
...
#endif
So, you are right - the code is portable and works as expected. But gcc do not treat "%8.8I64x"
as a format specifier, and it thinks that the format string " %8.8" PRIx64 ":%s"
has only one specifier - %s
, so gcc generate all these false-positive warnings.
I don't know c\c++ and other unix stuff, so i don't know how to do it in the right way.