Magic fixes like this are a probable sign you are experiencing memory corruption (out-of-bounds array access) and moving the array to the heap just hides the issue. As @fxm says, always use -exx to find out what's happening.
Search found 2096 matches
- May 03, 2024 18:27
- Forum: Beginners
- Topic: Program Exits With Array Problem
- Replies: 6
- Views: 419
- Mar 09, 2024 1:58
- Forum: Sources, Examples, Tips and Tricks
- Topic: The Travelling Salesman Problem
- Replies: 21
- Views: 1370
Re: The Travelling Salesman Problem
The first time I heard about the traveling salesman problem was in computer science class at university in the early 90s. The problem is NP-complete, as far as I can remember, and not solvable in polynomial time. It is good to hear that the solution to the problem has actually found practical appli...
- Feb 27, 2024 1:33
- Forum: Sources, Examples, Tips and Tricks
- Topic: polymorphism revisit - 2023
- Replies: 28
- Views: 3744
Re: polymorphism revisit - 2023
The AI wasn't totally wrong. The example is indeed a form of polymorphism, but it's static and resolved at compile time. I get the impression, though that you are seeking for an example of dynamic or run-time polymorphism. This is where an abstract base class defines a common method (called a virtua...
- Feb 21, 2024 1:15
- Forum: General
- Topic: Having a strange problem with a program
- Replies: 3
- Views: 636
Re: Having a strange problem with a program
Compile with '-exx'. That will add in additional runtime checking for things like bounds. When I compile with -exx and run your example, I get: $ ./tinybasic hello.bas Aborting due to runtime error 6 (out of bounds array access) at line 573 of tinybasic.bas::INITLEX2() So I think your problem is som...
- Feb 07, 2024 0:44
- Forum: Sources, Examples, Tips and Tricks
- Topic: Rounding numbers
- Replies: 48
- Views: 5104
Re: Rounding numbers
The root problem is that although both printf and print using do round, since the numbers are binary floating point the number might be in reality a tiny bit lower than the digit 5. For example you might think the number is 0.635, but it might actually 0.6349999. Adding a 5 in the correct digit does...
- Feb 06, 2024 20:23
- Forum: Sources, Examples, Tips and Tricks
- Topic: Rounding numbers
- Replies: 48
- Views: 5104
Re: Rounding numbers
I just read a trick for rounding numbers with printf. The trick is to add a 5 to the number, in the decimal place just past the digits you want to round to. For example, printf("%0.2f", 0.635 + 0.005). that guarantees it will round even as it truncates.
- Feb 04, 2024 22:42
- Forum: Sources, Examples, Tips and Tricks
- Topic: Free ChatGPT
- Replies: 12
- Views: 850
Re: Free ChatGPT
If code-generation AIs had access to real compilers to run their code through, and a little bit of testing smarts, then I'd rely on AI more in programming. The only time I've tried asking ChatGPT about some code in FreeBASIC (I asked about using GTK+ 3.x in FB), it happily generated some code for me...
- Jan 11, 2024 19:34
- Forum: General
- Topic: Circle bug?
- Replies: 7
- Views: 619
- Jan 08, 2024 14:51
- Forum: General
- Topic: Free Basic program size
- Replies: 9
- Views: 952
Re: Free Basic program size
That's the word I was looking for. "Compile Unit." Modularizing the code is well worth the time and effort. Each file becomes its own compile unit. Besides making incremental compile time much quicker, individual source files are easier to test in small pieces. There are some things you ne...
- Jan 07, 2024 22:41
- Forum: General
- Topic: Free Basic program size
- Replies: 9
- Views: 952
Re: Free Basic program size
Shouldn't be a problem, @JLThompson999. FB can handle that and much larger source files. Although I highly recommend splitting source code files up in to separate files (called modules) that can be compiled individually. That makes it much easier to maintain and document the code, and dramatically d...
- Dec 27, 2023 5:24
- Forum: Libraries Questions
- Topic: Trying to use an FB static library in a C program
- Replies: 5
- Views: 1236
Re: Trying to use an FB static library in a C program
True, although FB converting everything to upper case is a form of name mangling, which alias can help with. There's also the issue calling convention, which extern "C" or CDECL address. Although I believe FB's default is CDECL. I ran xlucas' test code on my LInux machine and it linked and...
- Dec 26, 2023 3:17
- Forum: Libraries Questions
- Topic: Trying to use an FB static library in a C program
- Replies: 5
- Views: 1236
Re: Trying to use an FB static library in a C program
Right. Short answer is name mangling. So you either put your function in an extern "c" block, or you use the CDECL keyword in your function definition and define an alias that will be used by the C code:
https://www.freebasic.net/wiki/KeyPgCdecl
https://www.freebasic.net/wiki/KeyPgFunction
https://www.freebasic.net/wiki/KeyPgCdecl
https://www.freebasic.net/wiki/KeyPgFunction
- Dec 21, 2023 15:54
- Forum: Community Discussion
- Topic: anyone remember this book?
- Replies: 6
- Views: 1042
Re: anyone remember this book?
Or search books.google.com. Here's one that matches your time period: https://books.google.ca/books/about/QBasic_Games_and_More.html?id=8JhdXDdSqdwC&redir_esc=y I cannot get a preview so I can't tell you exactly what's in it. Here's another one from the same time period: https://www.google.ca/bo...
- Dec 18, 2023 3:31
- Forum: Windows
- Topic: Win 11 console
- Replies: 26
- Views: 2212
Re: Win 11 console
caseih you may be right, geany launches the cmd like this: cmd.exe /Q /C %c I searched for almost an hour to find command line options for the terminal that would be equivalent to those options but all I found was a ton of "split" and "pane" but nothing that would answer my ques...
- Dec 17, 2023 16:16
- Forum: Windows
- Topic: Win 11 console
- Replies: 26
- Views: 2212
Re: Win 11 console
I'm sure changes will be needed in the FB runtime to properly support terminal. FB works great with Linux, so there's no reason it can't do the same on Windows with the Terminal. On Linux, as long as you don't use LOCATE, output can buffered and scrolled back to. I have not had the opportunity to te...