mercredi 21 mars 2018

Is it ok to use char* like a function type?

I read about char*, that it should be used and instead of it I should use just char[]. Does it concern also function types? I paste below this what I read and my code below.

will place "Hello world" in the read-only parts of the memory, and making s a pointer to that makes any writing operation on this memory illegal

char* GetModulePath()
{
    char ownPth[MAX_PATH];

    HMODULE hModule = GetModuleHandle(NULL);

    if (hModule != NULL)
    {
        GetModuleFileName(hModule, ownPth, (sizeof(ownPth)));
    }
    return ownPth;
}

So is it ok? Maybe instead of char* I should do it using const chars* ?

Aucun commentaire:

Enregistrer un commentaire