AdeptLanguage / Adept

The Adept Programming Language
GNU General Public License v3.0
119 stars 9 forks source link

does 'char' type exist in Adept? #63

Closed Spoiledpay closed 2 years ago

Spoiledpay commented 2 years ago

Hello! I didn't find the Char type in Adept's documentation. Does it exist in another form?

char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

IsaacShelton commented 2 years ago

@Spoiledpay

Yes, it's equivalent to ubyte.

import basics

func main {
    // -------------------------------------------
    //                 Example 1
    // -------------------------------------------
    greeting 6 ubyte = {'H'ub, 'e'ub, 'l'ub, 'l'ub, 'o'ub, 0x00ub}

    printf('%s\n', &greeting[0])
    printf('%s\n', greeting at 0)
    printf('%s\n', &greeting as *ubyte)

    // -------------------------------------------
    //                 Example 2
    // -------------------------------------------

    cstring *ubyte = 'Hi'
    printf('%s\n', cstring)

    // -------------------------------------------
    //                 Example 3
    // -------------------------------------------

    heap_cstring *ubyte = strdup(cstring)
    defer free(heap_cstring)

    printf('%s\n', heap_cstring)
}
Hello
Hello
Hello
Hi
Hi