Author Topic: Compiler fails on _UNSIGNED _BIT function parameters  (Read 3858 times)

0 Members and 1 Guest are viewing this topic.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Compiler fails on _UNSIGNED _BIT function parameters
« on: April 09, 2021, 07:06:43 am »
This code fails to compile in QB64 v1.3:

Code: QB64: [Select]
  1. PRINT foo$(0)
  2.  
  3. FUNCTION foo$ (my_variable AS _UNSIGNED _BIT)
  4.  
  5.    foo$ = "something"
  6.  


It also fails when using a variable suffix:

Code: QB64: [Select]
  1. PRINT foo$(0)
  2.  
  3. FUNCTION foo$ (my_variable~`)
  4.  
  5.    foo$ = "something"
  6.  


I thought maybe the "0" being passed in to my function was not being seen as an _UNSIGNED _BIT, but it still fails when using a typed variable:

Code: QB64: [Select]
  1. DIM UnsignedBit AS _UNSIGNED _BIT
  2.  
  3. UnsignedBit = 0
  4.  
  5. PRINT foo$(UnsignedBit)
  6.  
  7. FUNCTION foo$ (my_variable AS _UNSIGNED _BIT)
  8.  
  9.    foo$ = "something"
  10.  


Could someone test if that fails on QB64 v1.5?

I read the QB64 v1.4 and v1.5 changelog and decided an update wasn't needed for my current small project.


The error from the compiler is this:

Code: [Select]
In file included from ..\\temp\\main.txt:23,
                 from qbx.cpp:2171:
..\\temp\\data1.txt: In function 'qbs* FUNC_FOO(unsigned int*)':
..\\temp\\data1.txt:3:9: error: declaration of 'unsigned int* _FUNC_FOO_UBIT1_MY_VARIABLE' shadows a parameter
 uint32 *_FUNC_FOO_UBIT1_MY_VARIABLE=NULL;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

I read online that "shadows a parameter" has to do with a function parameter using the same name as a variable in the function, but it's failing on an empty function.


Breaking down the error message I can see:

Code: [Select]
_FUNC_FOO_UBIT1_MY_VARIABLE   unsigned int*
_FUNC_FOO_UBIT1_MY_VARIABLE   uint32*

I'm not super familiar with the C++ variable types, but it looks like there are two separate types of unsigned integers being used by QB64 in different areas, which is causing the compiler to interpret them as separate variables.


Questions:
  • Are _UNSIGNED _BIT variables not intended to be passed to FUNCTIONs?
    If so, it would be to have QB64 catch this error in the editor.
  • Or is there something else I'm missing in the way I'm calling the function?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #1 on: April 09, 2021, 07:26:54 am »
If I were you, I'd download 1.5 and see if the error still appears.
Shuwatch!

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #2 on: April 09, 2021, 07:46:35 am »
If I were you, I'd download 1.5 and see if the error still appears.

After the absolute nightmare I went through trying to get QB64 to work correctly on my 4K display originally (editor fullscreen issues, font scaling issues, font glitching issues), I'm hesitant to upgrade in case it messes it all up again.  I don't need any of the new features for my current project, and this bug is easily worked around by using INTEGER instead of _UNSIGNED _BIT.

If it is a v1.5 bug, then the devs can check it out.


Edit:
It says you're a QB64 dev, I imagine it would be easy enough for you to try 4 lines of code in your QB64.
« Last Edit: April 09, 2021, 07:49:31 am by Raven_Singularity »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #3 on: April 09, 2021, 08:15:30 am »
No need to be snippy. I wish you luck with your project.
Shuwatch!

Offline venex

  • Newbie
  • Posts: 7
    • View Profile
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #4 on: April 09, 2021, 08:48:56 am »
I'm hesitant to upgrade in case it messes it all up again.
You don't need to upgrade your current QB64 installation, you can unpack QB64 v1.5 to a separate folder and run it from there. Technically, you can have as many different QB64 versions as you want, without breaking any of them.

It says you're a QB64 dev, I imagine it would be easy enough for you to try 4 lines of code in your QB64.
Have you bought QB64 or paid for support to make such demands?

BTW. I checked the code and it still fails to compile on QB v1.5 with exactly the same error as in QB v1.4 and QB v1.3.
« Last Edit: April 09, 2021, 12:17:18 pm by venex »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #5 on: April 09, 2021, 12:49:19 pm »
@Raven_Singularity If you are still interested in trying to use _BIT types as function arguments then you can download the latest QB64 dev build here https://www.qb64.org/portal/development-build/ which contains the bug fix I have implemented. No more compilation error when using a _BIT argument.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #6 on: April 09, 2021, 01:54:41 pm »
Just to stir the pot, what good are bit types anyway?

They don't save any room (we had a discussion earlier mainly @SMcNeill provided tech info), you can't use them in UDT's... What does this type do that another byte or integer or long wont do just as well?

Maybe you need them in Declare Library from another language?


FellippeHeitor

  • Guest
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #7 on: April 09, 2021, 02:11:49 pm »
_BIT is best avoided.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #8 on: April 09, 2021, 02:17:30 pm »
@bplus _BITs aren't any good at all, yeah. They're more resource intensive and take more lines to declare (on the C++ side). It's not truly a bit anyways. But, the bug was there from at least v1.3 and it was a simple fix. Even if no one uses _BITs, it's good to have less potential compiler errors due to bad C++ syntax.
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #9 on: April 09, 2021, 02:31:12 pm »
Thanks guys for your confirmations. :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #10 on: April 09, 2021, 06:01:04 pm »
The *only* time where you might want to use bits is when bit packing an array.

DIM a(800000000) AS _BYTE is an 800MB array.
DIM b(800000000) AS _BIT is a 100MB array.

That’s a considerable reduction in disk and memory usage, and is the only time when it makes sense to use bits directly.

DIM B AS _BIT is *worthless.  The smallest space either in memory, or on your drive, is a byte.  By declaring B AS _BIT, you’re just taking that bite, manipulating only one bit in it, and then saving it.

Think of it like trying to compress a file of just 1 byte in size...

All you’re doing is adding complexity, speed reduction, and increased overhead by compressing your 1 byte file, and it’s basically the same when using bits.



As I’ve said before, think of a PC as a bus stop.  Buses drive back and forth between those stops, and they carry people inside them.  Everyone is familiar with buses and how they work, right?

Then think of it as bits = people.  Bytes = buses.  You can only drive buses from stop to stop (or from drive to memory register, in the case of bytes); not people.  The only time it makes sense to talk about those people is once they’re packed on the bus.

“A first bus out of Tucson ran into a brick wall yesterday, killing 3 passengers!”
“The first byte in this structure has 3 bits representing: male/female, living/dead, republican/democrat.”

Unless you’re bitpacking an array, use _BYTE.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compiler fails on _UNSIGNED _BIT function parameters
« Reply #11 on: April 09, 2021, 06:57:37 pm »
Ignore my post earlier about fixing the bug. It only fixed it for your particular instance. I have had to roll back that update. It shall remain a bug, it seems.
Shuwatch!