mrk-its / rust-mos

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
55 stars 7 forks source link

Arrays larger than 32 kB not possible #6

Closed mlund closed 1 year ago

mlund commented 2 years ago

The following gives a compiler error:

pub const DEFAULT_BASIC_AREA : *mut [u8; 38911] = (0x0801) as *mut [u8; 38911];

with the following message:

error[E0080]: values of the type `[u8; 38911]` are too big for the current architecture
  --> src/c64.rs:79:1
   |
79 | pub const DEFAULT_BASIC_AREA : *mut [u8; 38911] = (0x0801) as *mut [u8; 38911];
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
   = note: the raw bytes of the constant (size: 2, align: 1) {
               01 08                                           │ ..
           }

I'm not sure where this limitation comes from as the memory region is within the 16-bit address space of the 6502.

mlund commented 2 years ago

As discussed here, the reason is that the maximum array length is defined by isize::MAX == 32767. I think usize::MAX, i.e. 64 kB would have been more reasonable as the 8-bit systems are already quite limited. But perhaps difficult to change due to signed pointer arithmetics:

mlund commented 1 year ago

I'm not sure there's any solution to this(?), so fine to close.

mrk-its commented 1 year ago

Let's close it, it looks it is more upstream rust issue.