Author Topic: "Compilation failed" help?  (Read 919 times)

0 Members and 1 Guest are viewing this topic.

Offline Phlashlite

  • Newbie
  • Posts: 50
"Compilation failed" help?
« on: February 01, 2022, 10:39:20 pm »
Anybody know why this code throws a "Compilation failed" error?  I've never had one of those before.

It's probably something simple to do with my code but, I'm just too newb to see it... ...
Any help would be appreciated.


Code: QB64: [Select]
  1.  'For demo______________________________________________________________________
  2. DIM test(24) AS INTEGER
  3. FOR x = 0 TO 24
  4.     test(x) = INT(RND * 999)
  5.     PRINT test(x)
  6.  
  7. RADIX_SORT (test())
  8.  
  9. FOR x = 0 TO 24
  10.     LOCATE 1, 5
  11.     PRINT test(x)
  12.  
  13. '_____________________________________________________________________________
  14.  
  15.  
  16. length = ALGTH(ARR())
  17.  
  18.  
  19.  
  20. 'Function for radix sort
  21. SUB RADIX_SORT (ARR())
  22.  
  23.     'Find largest element in the Array
  24.     max = AMAX(ARR(), length)
  25.  
  26.     'Counting sort is performed based on place, like ones place, tens place and so on.
  27.     place = 1
  28.     WHILE max / place > 0
  29.         CALL COUNT_SORT(ARR(), place)
  30.         place = place * 10
  31.     WEND
  32.  
  33.  
  34. SUB COUNT_SORT (ARR(), PLACE)
  35.  
  36.     DIM oput(length)
  37.  
  38.     'Range of the number is 0-9 for each place considered.
  39.     DIM count(10)
  40.  
  41.     'Count number of occurrences in count array
  42.     FOR i = 0 TO length
  43.  
  44.         index = ARR(i) \ PLACE
  45.         idx = index MOD 10
  46.         count(idx) = count(idx) + 1
  47.  
  48.     NEXT
  49.  
  50.     'Change count[i] so that count[i] now contains actual position of this digit in output()
  51.     FOR i = 1 TO 10
  52.         count(i) = count(i) + count(i - 1)
  53.     NEXT
  54.  
  55.     'Build the output array
  56.     i = length - 1
  57.     WHILE i >= 0
  58.  
  59.         index = ARR(i) \ PLACE
  60.  
  61.         c = count(index MOD 10)
  62.         oput(c) = oput(c) - 1
  63.  
  64.         idx = index MOD 10
  65.         count(idx) = count(idx) - 1
  66.  
  67.     WEND
  68.  
  69.     i = 0
  70.     FOR i = 0 TO length
  71.         ARR(i) = oput(i)
  72.     NEXT
  73.  
  74.  
  75.  
  76. '______________________________________________________________________________
  77. FUNCTION AMAX (ARR(), NUM)
  78.     FOR i = 0 TO NUM
  79.         IF i > 0 THEN
  80.             x = ARR(i - 1)
  81.             y = ARR(i)
  82.             IF x >= y THEN
  83.                 tmx = x
  84.             ELSE
  85.                 tmx = y
  86.             END IF
  87.         END IF
  88.     NEXT
  89.     AMAX = tmx
  90.  
  91. '______________________________________________________________________________
  92. FUNCTION ALGTH (ARR())
  93.     ALGTH = UBOUND(ARR) - LBOUND(ARR)
  94.  

Marked as best answer by Phlashlite on February 01, 2022, 07:08:07 pm

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: "Compilation failed" help?
« Reply #1 on: February 01, 2022, 10:50:59 pm »
My guess would be a type mismatch.

DIM test(24) AS INTEGER

...

SUB RADIX_SORT (ARR())


....

RADIX_SORT (test())



Test is an integer array.

Radix_Sort wants an undefined array, which defaults to a SINGLE type.  This causes issues.



Second issue:  Passing your array inside parentheses.

RADIX_SORT (test())

This can cause issues.  Drop those parentheses and just pass it as:

RADIX_SORT test()



Correct the type mismatch, remove the parentheses, and I bet the issue will go away.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: "Compilation failed" help?
« Reply #2 on: February 01, 2022, 11:03:27 pm »
@SMcNeill 

I appreciate it.  I'll try that! 
I just never had that type of error before.

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: "Compilation failed" help?
« Reply #3 on: February 01, 2022, 11:06:41 pm »
My guess would be a type mismatch.
... ... ...

Correct the type mismatch, remove the parentheses, and I bet the issue will go away.

You were exactly right!  Thanks!