What naming conventions do you use with functions that allocate memory?

So, here are two functions that do almost the same thing.

What would you name each of them if you included both in your project?

void strToLower1(char* str)
{
    int len = strlen(str);

    int i;
    for (i=0; i<len; i++)
        str[i] = tolower(str[i]);
}

char* strToLower2(const char* inputStr)
{
    char* str = strdup(inputStr);
    strToLower1(str);
    return str;   // must be freed
}

EDIT: I modified the above example for correct code (sheesh)

+2
source share
4 answers

I really like Talismanic coding standards , especially naming conventions . An agreement may be applied here with the use of special names for copying, creating and accepting routines :

http://pcroot.cern.ch/TaligentDocs/TaligentOnline/DocumentRoot/1.0/Docs/books/WM/WM_67.html#0

, ,

, , :

, , delete Create...

, , , ... - , ().

, ...

, Adopt... ( ; .)

, (, ), ...

[] [] [] . Copyright © 1995 Taligent, Inc. .

createLowerCaseStr() copyAsLowercaseStr(). create copy , .

transformIntoLowercase() mutateIntoLowercase(), . Taligent, transform mutate , .

+2

strToLowerInPlace 'str', new_s = strToLowerInPlace(strdup(s)). , "InPlace" , , .

( , !)

+1

1st: char *copylo(char *dst, const char *src); ( !)
2: char *lowerize(char *data);

+1
  • tolower()
  • If you already have a function that creates the bottom scale in place, why are you redefining the code in the version out of place?
  • Naming is OK
0
source

All Articles