The International Simutrans Forum

 

Author Topic: Compile error when compiling with -std=c++03  (Read 426 times)

0 Members and 1 Guest are viewing this topic.

Offline ceeac

  • Devotee
  • *
  • Posts: 249
Compile error when compiling with -std=c++03
« on: September 04, 2020, 05:43:21 AM »
Code: [Select]
obj/baum.cc:321:87: error: unknown type name 'intptr_t'; did you mean '__intptr_t'?
        sint16 random = (sint16)( get_pos().x + get_pos().y + get_pos().z + slope + (sint16)(intptr_t)this );
                                                                                             ^~~~~~~~
                                                                                             __intptr_t
/usr/include/x86_64-linux-gnu/bits/types.h:206:25: note: '__intptr_t' declared here
__STD_TYPE __SWORD_TYPE __intptr_t;
                        ^
1 error generated.
intptr_t requires C++11. Is C++11 now allowed/required?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10635
  • Languages: De,EN,JP
Re: Compile error when compiling with -std=c++03
« Reply #1 on: September 04, 2020, 06:10:05 AM »
But MSCV does no know __intptr_t, only intptr_t. Actually, I had to add this otherwise GCC did not compile, even though the code was correct and MSVC 2015 did not complain, while it not supports C++11 fully.

So honestly Simutrans goes by what compiles on most systems.

Code: [Select]
intptr_t requires C++11.
Well, it just requires an include file like <stdint.h> which is around since 1998, http://www.qnx.com/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.dinkum_en_c99%2Fstdint.html

Offline TurfIt

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 1434
Re: Compile error when compiling with -std=c++03
« Reply #2 on: September 04, 2020, 07:13:43 PM »
From config.template:
Code: [Select]
# The following useful conditional compilation flags exist
#
# Needed to compile:
# NO_INTPTR_T: must be set if intptr_t is not available
However this is only used in ptrhashtable_tpl. Uses of intptr_t have appeared in baum.cc, schedule_gui.cc, and searchfolder.cc breaking this functionality.

As for <stdint.h>:
Code: [Select]
intptr_t uintptr_t Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.
Optional: These typedefs may not be defined in some library implementations.*


Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10635
  • Languages: De,EN,JP
Re: Compile error when compiling with -std=c++03
« Reply #3 on: September 05, 2020, 01:04:33 PM »
Thank you, I moved this code to simtypes.h in r9212

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4869
  • Languages: EN, DE, AT
Re: Compile error when compiling with -std=c++03
« Reply #4 on: September 05, 2020, 05:23:51 PM »
These two commits do not compile. I tried to repair this. I do not know whether this solves the original bug report.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5691
  • Languages: EN, NO
Re: Compile error when compiling with -std=c++03
« Reply #5 on: September 08, 2020, 05:11:35 AM »
Well, it just requires an include file like <stdint.h> which is around since 1998
Since stdint.h is part of C99, which in turn was not part of C++ until C++11, I think it might be legal for a compiler to disable that file somehow unless either pure C99 or higher, or C++11 or higher, is selected. Furthermore, it is not mandatory, but I guess that is just a provision for architectures where pointers behave very strangely.