0

So, I decided to test out a new C++ turtle-style graphics library. I decided to test it out by making the fibonacci spiral. however, upon running the program, it stops in the middle. I checked what was going on, and the fibonacci value had reversed to -2147483647, as if it was compiled in 32-bit. Can someone please help? I compiled it with g++ on Windows. Note: I was using a vector to store the values. Here's my code:

//Includes and namespaces
#include "Cturtle.hpp"
#include<iostream>
namespace ct = cturtle;

std::vector<long int> fibonacci = {1, 2}; //This vector stores the fib sequence
ct::TurtleScreen scr; //Create a new Screen
ct::Turtle turtle(scr); //Create a new turtle on the screen

int main() {
    turtle.speed(ct::TS_FASTEST); //Set the turtle's speed to max
    
    while(true) {
        for(int i = 0; i < fibonacci.back(); i++) {
            
            fibonacci.push_back(fibonacci.back() + fibonacci.back()-1); //Add a new value to the fibonacci vector based off the previous two
            std::cout << fibonacci.back() << '\n'; //This is here for debug
            turtle.forward(1); //Move the turtle 1 step forward
            turtle.right(90 / fibonacci.back()); //Turn according to 90 divided by the current fibonacci value
        }
    }
}
1
  • 1
    just because you compile as 64 bit does not mean that all datatypes automagically are 64bit wide Commented Mar 10, 2021 at 11:47

1 Answer 1

5

MinGW uses the MSVC-friendly LLP64 data model.

In LLP64, int and long int are both 32 bits, regardless of platform bitness (32/64 bit).

To get a 64-bit data type, use long long or int64_t.

e.g. std::vector<long long>. And also here: for(long long i = 0; ...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.