:: Re: [DNG] C vs ADA : advice sought
Pàgina inicial
Delete this message
Reply to this message
Autor: kc-devuan
Data:  
A: dng
Assumpte: Re: [DNG] C vs ADA : advice sought
2 Oct 2024 02:01:16 Erik Christiansen via Dng <dng@???>:

> Setting specific bits in hardware
>
> registers at fixed addresses does not benefit from language abstraction,
>
> so the closer the language is to the hardware, the better.
>


Ada is as close to the hardware as C. You can do it the same way minus horrible macros, but I disagree. Adas record overlays make this easier and less error prone. There is also built in validation when this is applied to registers received via spi/i2c by using `Valid on the record components. It is rather beautiful and my favourite Ada feature that other languages try to copy but cannot without copying Adas type system too.

"https://github.com/AdaCore/Ada_Drivers_Library/blob/master/arch/ARM/STM32/svd/stm32f429x/stm32_svd-rng.ads"


> "dereferencing" obfuscates. An array is in reality only a pointer to its
>
> base address plus an offset to an element of it.
>


I have read a book that refutes that slightly but arrays are much better in Ada and safer. They can even be packed with 1 bit per boolean just by "with pack".

> -nostdlib, to reduce code size, when that suits. I don't know if an ADA
>
> program can be trimmed to under 1 kB in size - 500 assembler
>
> instructions, including hardware initialisation and all application code.)
>


I would need to check as I have never had an issue. A tiny micro still with 10 years of guaranteed support is 32k these days. I find introducing assembly easier in Ada than C actually.

>
> registers. I have programmed a 3-channel LED dimmer with serial
>
> communications for remote control on that chip - but not in C++.


Sounds like you wouldn't even need software at all and it could just be done in hardware. I'm amazed at what hardware engineers can do without any software.

Ada is more work upfront but it is more cost effective over the lifetime of a program than C or Java due to being optimised for reading unlike C and Rust.