Yes thank you Andrey, 
I noticed this shortly after sending the example in the email. I redid the 
procedure on the code below which is not optimized by the Go compiler, and 
I get the same conclusions as before, you can check.

Best,
Karolina


































*switch-go-improved/main.go----------------------------------------------package
 
mainimport (    "fmt"    "os"    "strconv")func main() {    // this is so 
that the Go compiler doesn't optimize drasticvally the code    if 
os.Args[1] == "" {        fmt.Println("Please provide a number (1, 5, 10, 
or other)")        os.Exit(1)    }    x, err := strconv.Atoi(os.Args[1])    
if err != nil {        fmt.Println("Invalid number")        os.Exit(1)    
}    switch x {    case 1:        fmt.Println("One")    case 5:        
fmt.Println("Five")    case 10:        fmt.Println("Ten")    default:      
  fmt.Println("Other")    }}*

*----------------------------------------------*
On Tuesday, December 3, 2024 at 3:49:54 PM UTC+1 Andrey Bokhanko wrote:

> понедельник, 2 декабря 2024 г. в 13:25:22 UTC+3, Karolina GORNA: 
>
>
> *switch-go/main.go*----------------------------------------------
> package main
>
> import "fmt"
>
> func main() {
>     x := 10
>     switch x {
>     case 1:
>         fmt.Println("One")
>     case 5:
>         fmt.Println("Five")
>     case 10:
>         fmt.Println("Ten")
>     default:
>         fmt.Println("Other")
>     }
> }
>
>  
> Karolina, in this specific test case the whole switch got optimized out, 
> as it's clear it always computes to 10, so only one case remains.
>
> Andrey
>
>
-- 

Les informations contenues dans ce message électronique ainsi que celles 
contenues dans les documents attachés sont strictement confidentielles et 
sont destinées à l'usage exclusif du (des) destinataire(s) nommé(s).
Toute 
divulgation, distribution ou reproduction, même partielle, en est 
strictement interdite sauf autorisation écrite et expresse de l’émetteur.
Si vous recevez ce message par erreur, veuillez le notifier immédiatement à 
son émetteur par retour, et le détruire ainsi que tous les documents qui y 
sont attachés.


The information contained in this email and in any 
document enclosed is strictly confidential and is intended solely for the 
use of the individual or entity to which it is addressed.
Partial or total 
disclosure, distribution or reproduction of its contents is strictly 
prohibited unless expressly approved in writing by the sender.
If you have 
received this communication in error, please notify us immediately by 
responding to this email, and then delete the message and its attached 
files from your system.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/e898fc8c-d8a2-4d69-aee0-af3e66de9cf8n%40googlegroups.com.

Reply via email to