Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using {fmt} on IBM i (AS/400) 7.3 ILE C++ compiler #1059

Closed
kunichik opened this issue Feb 26, 2019 · 9 comments
Closed

Using {fmt} on IBM i (AS/400) 7.3 ILE C++ compiler #1059

kunichik opened this issue Feb 26, 2019 · 9 comments

Comments

@kunichik
Copy link

I added the include/fmt folder to my project
when I include fmt/printf.h in the program, the IBM i 7.3 ILE C++ compiler,
which doesn't fully implement C++11,
I get the following errors:

../fmt/core.h(481) : error : at column 021 - The name "typename std::enable_if" is not a type.

../fmt/core.h(196) : error : at column 001 - The name "typename std::add_rvalue_reference" is not a type.

../fmt/core.h(210) : error : at column 015 - The name "typename std::make_unsigned" is not a type.

../fmt/core.h(662) : error : at column 025 - The text "<" is unexpected. "std::conditional" may be undeclared or ambiguous.

../fmt/core.h(665) : error : at column 070 - The name lookup for "long_type" did not find a declaration.

../fmt/core.h(665) : warning : at column 070 - Declarations for non-dependent names are resolved in the template definition.

../fmt/core.h(665) : warning : at column 070 - "long_type" does not depend on a template argument.

../fmt/core.h(670) : error : at column 020 - The name lookup for "ulong_type" did not find a declaration.

../fmt/core.h(670) : warning : at column 020 - "ulong_type" does not depend on a template argument.

../fmt/core.h(874) : error : at column 027 - "std::forward" is not declared.

../fmt/format.h(597) : error : at column 003 - The template argument must be a type, to match the template parameter.

../fmt/format.h(672) : error : at column 048 - The name "typename std::is_void" is not a type.

../fmt/format.h(677) : error : at column 026 - The text "<" is unexpected.

../fmt/format.h(999) : error : at column 010 - "internal::copy_str" is not declared.

../fmt/format.h(1661) : error : at column 019 - The name lookup for "to_unsigned" did not find a declaration.

../fmt/format.h(1661) : warning : at column 019 - "to_unsigned" does not depend on a template argument.

../fmt/format.h(2019) : error : at column 010 - The text "{" is unexpected.

../fmt/format.h(2900) : error : at column 007 - "internal::is_negative" is not declared.

../fmt/format.h(3258) : error : at column 003 - "internal::check_format_string" is not declared.

../fmt/format.h(398) : error : at column 034 - "internal::to_unsigned" is not declared.

../fmt/ostream.h(78) : error : at column 029 - The text "<" is unexpected. "std::make_unsigned" may be undeclared, ambiguous, or may require "typename" qualification.

@kunichik kunichik changed the title using fmt on IBM system i using fmt on IBM i 7.3 ILE C++ compiler Feb 26, 2019
@vitaut
Copy link
Contributor

vitaut commented Feb 28, 2019

{fmt} version 5.x requires a subset of C++11 including std::enable_if. Version 4.1 supports older compilers so you might try that instead.

@kunichik
Copy link
Author

kunichik commented Mar 1, 2019

I downloaded version 4.x and defined the macro FMT_HEADER_ONLY.
It's all right!
But I get the following errors:
../fmt/format.h(2136) : error : at column 040 - "uintptr_t" is not declared.

Note:
The IBM i (AS/400) has 64 bit integers and 128 bit pointers, so there is no such type in
cstdint or "stdint.h"

Can intptr_t be replaced by another type, e.g. unsigned int ?

I've replaced this type as follows:

void write_pointer(const void *p) {
    spec_.flags_ = HASH_FLAG;
    spec_.type_ = 'x';
    //writer_.write_int(reinterpret_cast<uintptr_t>(p), spec_);
    writer_.write_int(reinterpret_cast<unsigned int>(p), spec_);
}

and my test programm works.

@kunichik kunichik changed the title using fmt on IBM i 7.3 ILE C++ compiler Using {fmt} on IBM i (AS/400) 7.3 ILE C++ compiler Mar 1, 2019
@vitaut
Copy link
Contributor

vitaut commented Mar 1, 2019

Can intptr_t be replaced by another type, e.g. unsigned int ?

AFAIK the integral type should be large enough for the cast to be valid. A better option is to have a struct of two 64-bit integers, bitcast the pointer to it and then write those two integers.

@vitaut
Copy link
Contributor

vitaut commented Mar 1, 2019

or use non-standard 128-bit integral type if available.

@kunichik
Copy link
Author

kunichik commented Mar 1, 2019

or use non-standard 128-bit integral type if available.

128-bit integral type isn't available

but i have uint64_t in stdint.h
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rtref/stdinth.htm

what if i typedef here something like this:

#ifdef __UINTPTR_T_AS400
  typedef uint64_t uintptr_t 
#endif

?

@vitaut
Copy link
Contributor

vitaut commented Mar 2, 2019

what if i typedef here something like this

Sure if you are OK with the cast being not particularly kosher.

@kunichik
Copy link
Author

kunichik commented Mar 2, 2019

Sure if you are OK with the cast being not particularly kosher.

OK, what if you change reinterpret_cast to uintptr_t for the pointer to another cast ?

e.g. inside write_int method you cast T value to UnsignedType.
what if you replace

writer_.write_int(reinterpret_cast<uintptr_t>(p), spec_);

to

typedef typename internal::IntTraits<T>::MainType UnsignedType;
writer_.write_int(reinterpret_cast<UnsignedType>(p), spec_);

?

@vitaut
Copy link
Contributor

vitaut commented Mar 3, 2019

This will have the same issue. As I wrote earlier:

A better option is to have a struct of two 64-bit integers, bitcast the pointer to it and then write those two integers.

@vitaut
Copy link
Contributor

vitaut commented Apr 6, 2019

bd81771 adds support for platforms without uintptr_t. You still need a compiler with some C++11 support, but a PR to backport this to the 4.x branch of {fmt} would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants