Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interesting compile error
#1
I'm working on an electrical engineering study app. In the code, I have a dynamic array ($DYNAMIC) that I initially declare as:

DIM SHARED AS STRING segment(1).

Further on in the program, as new segments are added, the program does this:

REDIM _PRESERVE segment AS STRING.

BUT! When I am loading a data file of an existing study, the line is:

REDIM _PRESERVE segment * 57 AS STRING.

I need a 57-character string to fit the width of an InForm listbox. The interesting thing is, the IDE doesn't indicate an error, but when I compile the app I get:

'C++ Compilation failed (Check .\internal\temp\compilelog.txt) error in the IDE 

Looking at the compile log, I get:

Code: (Select All)

internal\c\c_compiler\bin\c++.exe  -std=gnu++17 -fno-strict-aliasing -Wno-conversion-null -DGLEW_STATIC -DFREEGLUT_STATIC -Iinternal\c\libqb/include -Iinternal\c/parts/core/freeglut/include -Iinternal\c/parts/core/glew/include -DDEPENDENCY_IMAGE_CODEC -DDEPENDENCY_SOCKETS -DDEPENDENCY_PRINTER -DDEPENDENCY_ICON -DDEPENDENCY_NO_SCREENIMAGE -DCURL_STATICLIB -Iinternal\c/parts/network/http/include internal\c/qbx.cpp -c -o internal\c/qbx.o
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4689:5: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4689 | if (__ARRAY_STRING57_SEGMENTS[2]&2){
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |    __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4692:25: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'
4692 | ((mem_lock*)((ptrszint*)__ARRAY_STRING57_SEGMENTS)[8])->id=(++mem_lock_id);
      |                        ^
internal\c/../temp/main.txt:4693:5: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4693 | if (__ARRAY_STRING57_SEGMENTS[2]&1){
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |    __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4694:5: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4694 | if (__ARRAY_STRING57_SEGMENTS[2]&4){
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |    __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4695:28: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4695 | cmem_dynamic_free((uint8*)(__ARRAY_STRING57_SEGMENTS[0]));
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                            __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4697:14: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4697 | free((void*)(__ARRAY_STRING57_SEGMENTS[0]));
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~
      |              __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4700:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4700 | __ARRAY_STRING57_SEGMENTS[4]= 0 ;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4701:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4701 | __ARRAY_STRING57_SEGMENTS[5]=( 1 )-__ARRAY_STRING57_SEGMENTS[4]+1;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4701:36: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4701 | __ARRAY_STRING57_SEGMENTS[5]=( 1 )-__ARRAY_STRING57_SEGMENTS[4]+1;
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                    __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4702:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4702 | __ARRAY_STRING57_SEGMENTS[6]=1;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4703:5: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4703 | if (__ARRAY_STRING57_SEGMENTS[2]&4){
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
      |    __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4704:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4704 | __ARRAY_STRING57_SEGMENTS[0]=(ptrszint)cmem_dynamic_malloc(__ARRAY_STRING57_SEGMENTS[5]*57);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4704:60: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4704 | __ARRAY_STRING57_SEGMENTS[0]=(ptrszint)cmem_dynamic_malloc(__ARRAY_STRING57_SEGMENTS[5]*57);
      |                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                            __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4705:16: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4705 | memset((void*)(__ARRAY_STRING57_SEGMENTS[0]),0,__ARRAY_STRING57_SEGMENTS[5]*57);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4705:48: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4705 | memset((void*)(__ARRAY_STRING57_SEGMENTS[0]),0,__ARRAY_STRING57_SEGMENTS[5]*57);
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4707:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4707 | __ARRAY_STRING57_SEGMENTS[0]=(ptrszint)calloc(__ARRAY_STRING57_SEGMENTS[5]*57,1);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4707:47: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4707 | __ARRAY_STRING57_SEGMENTS[0]=(ptrszint)calloc(__ARRAY_STRING57_SEGMENTS[5]*57,1);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                              __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4708:6: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4708 | if (!__ARRAY_STRING57_SEGMENTS[0]) error(257);
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~
      |      __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:4710:1: error: use of undeclared identifier '__ARRAY_STRING57_SEGMENTS'; did you mean '__ARRAY_STRING_SEGMENTS'?
4710 | __ARRAY_STRING57_SEGMENTS[2]|=1;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~
      | __ARRAY_STRING_SEGMENTS
internal\c/../temp/global.txt:81:11: note: '__ARRAY_STRING_SEGMENTS' declared here
  81 | ptrszint *__ARRAY_STRING_SEGMENTS=NULL;
      |          ^
In file included from internal\c/qbx.cpp:1742:
internal\c/../temp/main.txt:29574:181: warning: implicit conversion from 'int' to 'uint8_t' (aka 'unsigned char') changes value from 256 to 0 [-Wconstant-conversion]
29574 | *(uint8*)(((char*)_FUNC_ICONPREVIEW_ARRAY_UDT_ENTRY[0])+((array_check((*_FUNC_ICONPREVIEW_LONG_I)-_FUNC_ICONPREVIEW_ARRAY_UDT_ENTRY[4],_FUNC_ICONPREVIEW_ARRAY_UDT_ENTRY[5]))*16))= 256 ;
      |                                                                                                                                                                                  ~ ^~~
1 warning and 19 errors generated.
mingw32-make: *** [Makefile:413: internal\c/qbx.o] Error 1

Obviously, it must be an error to redim a string array with a fixed length after it was DIM'ed without a fixed length. If this is the proper behavior, the wiki doesn't indicate it. What is interesting is that the IDE didn't flag the error.

Thoughts?
It's not the having, it's the doing.
Reply
#2
Which version of QB64-PE are you using:

Quote:DIM SHARED AS STRING segment(1).

REDIM _PRESERVE segment AS STRING.

REDIM _PRESERVE segment * 57 AS STRING.

The latter two lines are completly wrong, that's not the way how array (re)dimming works. If I paste the above lines into the IDE I immediatly get syntax errors and arn't even able to start compiling the code.
Reply
#3
cannot even change the type after using erase:

Code: (Select All)
redim test(1 to 10) as string

test(1) = "test me"
erase test

redim test(1 to 10) as integer

test(1) = 10000

print "That's all the test folks!"
end
i get "name already in use" from the command line.  boy i really really hate this error message.  could something else be displayed instead?

the compilation try revealed above.  tried to refigure a string array into an ordinary single string variable.  then from a variable-length string to a fixed-length string.  cannot use the same name for more than one of those items.  this was enforced since quickbasic.
Reply
#4
(05-19-2025, 06:31 AM)RhoSigma Wrote: Which version of QB64-PE are you using:

Quote:DIM SHARED AS STRING segment(1).

REDIM _PRESERVE segment AS STRING.

REDIM _PRESERVE segment * 57 AS STRING.

The latter two lines are completly wrong, that's not the way how array (re)dimming works. If I paste the above lines into the IDE I immediatly get syntax errors and arn't even able to start compiling the code.

4.1.0.

Yes, I see that the redim dimension is missing in what I typed. My bad, it was late for me. I didn't copy the code. In the program the dimensions are there.

Initial declaration:                     DIM SHARED AS STRING wires(20), filename, segments(1) 

Doesn't cause compiler errors:    REDIM _PRESERVE AS STRING segments(iy)

Causes compiler errors:              REDIM _PRESERVE AS STRING * 57 segments(iy)

The point was that redimming as a fixed length string resulted in the compiler errors, but the IDE didn't flag that something was amiss.
It's not the having, it's the doing.
Reply
#5
(05-19-2025, 11:32 AM)hsiangch_ong Wrote: cannot even change the type after using erase:

Code: (Select All)
redim test(1 to 10) as string

test(1) = "test me"
erase test

redim test(1 to 10) as integer

test(1) = 10000

print "That's all the test folks!"
end
i get "name already in use" from the command line.  boy i really really hate this error message.  could something else be displayed instead?

the compilation try revealed above.  tried to refigure a string array into an ordinary single string variable.  then from a variable-length string to a fixed-length string.  cannot use the same name for more than one of those items.  this was enforced since quickbasic.
I'm not a guru, so take this for what it's worth:
The Wiki says Erase changes the VALUES, so I guess the array is still there.

I find this works:

ReDim test(1 To 10) As String
test(1) = "test me"
Erase test
ReDim test%(1 To 10)
test%(1) = 10000

Print "That's all the test folks!"
End
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#6
(05-19-2025, 11:42 AM)bobalooie Wrote:
(05-19-2025, 06:31 AM)RhoSigma Wrote: Which version of QB64-PE are you using:

Quote:DIM SHARED AS STRING segment(1).

REDIM _PRESERVE segment AS STRING.

REDIM _PRESERVE segment * 57 AS STRING.

The latter two lines are completly wrong, that's not the way how array (re)dimming works. If I paste the above lines into the IDE I immediatly get syntax errors and arn't even able to start compiling the code.

4.1.0.

Yes, I see that the redim dimension is missing in what I typed. My bad, it was late for me. I didn't copy the code. In the program the dimensions are there.

Initial declaration:                     DIM SHARED AS STRING wires(20), filename, segments(1) 

Doesn't cause compiler errors:    REDIM _PRESERVE AS STRING segments(iy)

Causes compiler errors:              REDIM _PRESERVE AS STRING * 57 segments(iy)

The point was that redimming as a fixed length string resulted in the compiler errors, but the IDE didn't flag that something was amiss.

Yes, with the dimensions it looks more correct now. However, you can't REDIM a variable length string into a fixed length one. That would imply not only changing the dimensions but also the TYPE of the array. And you are correct that the IDE should warn here at least with a "Name already in use" error, so you know you can't use the same array name one time for variable and another time for fixed length strings.

However, when I try to do this here, then I still can't compile it because the IDE gets trapped into an endless loop checking the code as soon as I typed it. So here's definitly something weird going on.
Reply
#7
Why not make original Dim Shared as String * 57 ?

or are you just fascinated by the inconsistency between IDE not catching error and compiler catching it?
b = b + ...
Reply
#8
(05-19-2025, 06:14 PM)bplus Wrote: Why not make original Dim Shared as String * 57 ?

or are you just fascinated by the inconsistency between IDE not catching error and compiler catching it?

I originally did that, but as I was working through the program I realized I really shouldn't fix the length for every case. Changed my mind. So, I went back to edit the DIM and REDIMs to remove the fixed length specification and just missed one. It was the rogue line that started all the fun.

I'd rather not be fascinated by IDE inconsistencies. I first thought I had accidentally broken my installation. Actually, looking at the compiler log closely helped me pin down that I still had a rogue line.
It's not the having, it's the doing.
Reply
#9
Inconsistencies life's full of them, good to get some enjoyment out of them yeah!
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)