_Symbols _with _leading _underscores

j my.email at gmail.com
Sun Dec 18 04:40:48 UTC 2022


On Saturday, 17 December 2022 at 02:42:22 UTC, Paul wrote:
> I see code like this from time to time.  Are the leading 
> underscores significant, in general, in the D language?  Is it 
> just programmer preference? Is it a coding practice, in 
> general, that is common...even outside of D?  Thanks for any 
> assistance.
>
> From: 
> http://dpldocs.info/this-week-in-d/Blog.Posted_2022_10_10.html#hello-arduino
>
> ```d
> import ldc.llvmasm;
>
> // Ports from the delay_basic.h in the thing
> void _delay_loop_1(ubyte __count) {
> 	// this template param is required to avoid
> 	// assertion `!Call.getType()->isVoidTy() && "Bad inline 
> asm!"' failed.
>
>         __asm!ubyte (
>                 "1: dec $0\n\tbrne 1b",
>                 "=r,0", (__count)
>         );
> }
> void _delay_loop_2(ushort __count) {
>         __asm!ushort (`
> 	1: sbiw $0,1
> 	brne 1b
> 	`,
> 	`=w,0`,
> 	__count);
> }
>
> // port from delay.h in arduino thing
> enum F_CPU = 1_000_000UL;
>
> // this was _delay_ms but i did something wrong and changed 
> double to int and i still don't love it
> void _delay(int __ms) {
> 	ushort __ticks;
> 	ulong __tmp = (F_CPU * __ms) / 4000;
> 	if(__tmp < 1)
> 		__ticks = 1;
> 	else if(__tmp > 65_535) {
> 		__ticks = cast(ushort) (__ms * 10.0);
> 		while(__ticks) {
> 			_delay_loop_2(cast(ushort) (((F_CPU) / 4e3) / 10));
> 			__ticks--;
> 		}
> 		return;
> 	} else
> 		__ticks = cast(ushort) __tmp;
> 	_delay_loop_2(__ticks);
> }
> ```



C and C++.


More information about the Digitalmars-d-learn mailing list