Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-11

Power operator fails in ordinal range definition

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth
to Hairy Pixels

Hairy Pixels via fpc-pascal schrieb am
Do., 14. Nov. 2024, 06:24:

Show quoted text 8 lines
This gives me "Error in type definition”. A bug? type TMyRec = record type T = 0..256**4; end;

The **-operator is not *implemented* by the compiler. It's provided through the Math unit. Thus you can't use it in constant declarations.

Regards,
Sven

Reply by email

Hairy Pixels
to Sven Barth

On Nov 14, 2024 at 1:53:17 PM, Sven Barth via fpc-pascal <

Show quoted text 5 lines
wrote: The **-operator is not *implemented* by the compiler. It's provided through the Math unit. Thus you can't use it in constant declarations.

Why is that? That means you can do powers in types or constants right?

Regards,
Ryan Joseph

Reply by email

Adriaan van Os
to Hairy Pixels
Hairy Pixels wrote 8 lines
On Nov 14, 2024 at 1:53:17 PM, Sven Barth via fpc-pascal < > wrote: > The **-operator is not *implemented* by the compiler. It's provided > through the Math unit. Thus you can't use it in constant declarations. Why is that? That means you can do powers in types or constants right?

Only a limited numbers of functions are implemented as compile-time functions. This is so in every compiler.

Regards,

Adriaan

Reply by email

Sven Barth
to Hairy Pixels: On Nov 14, 2024 at 1:53:17 PM, Sven Barth via fpc-pascal < Why is that? That means you…

Hairy Pixels via fpc-pascal schrieb am
Do., 14. Nov. 2024, 08:03:

Show quoted text 9 lines
On Nov 14, 2024 at 1:53:17 PM, Sven Barth via fpc-pascal < > wrote: > The **-operator is not *implemented* by the compiler. It's provided > through the Math unit. Thus you can't use it in constant declarations. > Why is that?

Because it wasn't deemed necessary that the compiler itself provides this operator.

That means you can do powers in types or constants right?

I assume you mean "can't". In that case, yes, that is not possible.

Regards,
Sven

Reply by email

Hairy Pixels
to Sven Barth

On Nov 14, 2024 at 8:11:53 PM, Sven Barth via fpc-pascal <

Show quoted text 5 lines
wrote: Because it wasn't deemed necessary that the compiler itself provides this operator.

You can use it to create ordinal types from bytes using a generic. I was trying to do something like this. If you do other operations on constants it makes to include powers too. Of course you can solve this a number of other ways too but I preferred this one.

type
  SomeInt<const A, B: Byte> = record
    header: 0..(256**A) - 1;
    footer: 0..(256**B) - 1;
  end;

SomeInt<4, 3>

Regards,
Ryan Joseph

Reply by email