post  Favorite naming convention?

Bazzy (4093)   Link to this post
LOL:
1
2
void *p=(void *)&p;
std::cout << p << '\n' << *((void**)p) << '\n' << &p;

chrisname (2468)   Link to this post
void *p=(void *)&p;

That's impossible, p is a pointer to void, not a pointer to a pointer...

Edit: But... it compiles! It doesn't segfault! I can print the address of p! HOW?
Last edited on
Bazzy (4093)   Link to this post
A pointer to void can point to any type
chrisname (2468)   Link to this post
OH.
firedraco (2540)   Link to this post
I name my classes like this:

class object;
and make instances of them like this:
object Object;

^_^
Bazzy (4093)   Link to this post
I do the opposite
TaikoDragon (27)   Link to this post
I use Camel case then naming my classes:
class SomeObjectClass;
and variables(local and global) + member functions like this:
1
2
3
4
int someVariable;
class SomeClass{
    int memberFunction();
}

non-member functions and namespaces use Camel case just like classes.

I will suffix most points with "Ptr" unless it's very local which then I assume you read the declaration.
1
2
3
4
5
6
7
8
namespace SomeNameSpace {
    void SomeFunction(void){
        int* anIntPtr = NULL;
        for(unsigned int i = 0; i < *anIntPtr; i++){
            int* veryTightScopeInt;
        }
    }
}

also I group the "*" with the type unless I'm making more than once declaration on the line.
Last edited on
computerquip (859)   Link to this post
Strange as it is, my C and C++ code conventions are different. For C, I go with gnome's crappy way of function naming eg.: this_is_a_very_long_function_lol( int * thisIsAVariable) compare to my C++ stile which goes something like int * SetRotation( int *pNumber). The C++ may have no lower case variables depending on it's status. If it's global, it starts with a g eg gGlobal. If it's just some random stack fiend, it goes something: int MyVariable; This is just something I grew into I guess...
jsmith (3728)   Link to this post
I'm a bit behind on this thread, but...

@chrisname:

You should never define your own symbols that begin with underscores; all such symbols are reserved by
compilers and/or library writers.

There are in many cases programmatic solutions to preventing "internal" functions from being called.
Make "internal" class member functions (if they need to be class members) private. For free functions
that are used in a single .cpp file, do not declare them in the header; rather make them static functions
in the .cpp file and/or put them in an unnamed namespace within the .cpp file.
chrisname (2468)   Link to this post


You should never define your own symbols that begin with underscores; all such symbols are reserved by
compilers and/or library writers.

There are in many cases programmatic solutions to preventing "internal" functions from being called.
Make "internal" class member functions (if they need to be class members) private. For free functions
that are used in a single .cpp file, do not declare them in the header; rather make them static functions
in the .cpp file and/or put them in an unnamed namespace within the .cpp file.

That's what I use them for; so that people won't call functions I don't want them to.
However I will take your advice and make them static.

Pages: [1] [2]


This topic is archived - New replies not allowed.