Re: Question about ubyte x overflow, any safe way?

2019-08-05 Thread Patrick Schluter via Digitalmars-d-learn

On Monday, 5 August 2019 at 18:21:36 UTC, matheus wrote:

On Monday, 5 August 2019 at 01:41:06 UTC, Ali Çehreli wrote:

...
Two examples with foreach and ranges. The 'ubyte.max + 1' 
expression is int. The compiler casts to ubyte (because we 
typed ubyte) in the foreach and we cast to ubyte in the range:

...


Maybe it was a bad example of my part (Using for), and indeed 
using foreach would solve that specific issue, but what I'm 
really looking for if there is a flag or a way to check for 
overflow when assigning some variable.


ubyte u = 260;  // Here should be given some warning or throw 
exception.


It's ubyte, but it could be any other data type.



Yes, no question. It's checkedint that you should use. It was 
written exactly for that purpose.






Re: Question about ubyte x overflow, any safe way?

2019-08-05 Thread matheus via Digitalmars-d-learn

On Monday, 5 August 2019 at 01:41:06 UTC, Ali Çehreli wrote:

...
Two examples with foreach and ranges. The 'ubyte.max + 1' 
expression is int. The compiler casts to ubyte (because we 
typed ubyte) in the foreach and we cast to ubyte in the range:

...


Maybe it was a bad example of my part (Using for), and indeed 
using foreach would solve that specific issue, but what I'm 
really looking for if there is a flag or a way to check for 
overflow when assigning some variable.


ubyte u = 260;  // Here should be given some warning or throw 
exception.


It's ubyte, but it could be any other data type.

Thanks anyway,

Matheus.



Re: How to get name of my application (project)

2019-08-05 Thread Jacob Carlborg via Digitalmars-d-learn

On 2019-08-03 17:58, Jonathan M Davis wrote:


Also, the first element in the array passed to main is the name of the
executable.


No, what's passed to "main" is the path to however the application was 
invoked, not the executable. If you invoke it as "./foo" it will pass 
"./foo" to the "main" function. If you invoke it as "/usr/local/bin/foo" 
it will pass "/usr/local/bin/foo" to the "main" function. That's at 
least how it works on macOS.


"thisExePath" will give you the full path to the executable regardless 
how if it was invoked. It will resolve symlinks as well.


So it depends on what's needed. "name of application" is a bit diffuse 
statement.


--
/Jacob Carlborg