
Originally Posted by
Ynot
There's certain things that are the "right way" in C, but the "wrong way" in C++ (and vice versa)
Arrays being the biggy
Arrays are exactly the same in C and C++.
He's right about the right and wrong ways being different in C and C++
Critical section in C
Code:
void CriticalMethod(void){
pthread_mutex_lock(somelock);
//some critical stuff
if (boolean){
pthread_mutex_unlock(somelock); //have to unlock in every exit path
return;
}
//more critical stuff
pthread_mutex_unlock(somelock);
}
Critical section in C++
Code:
//Autolock.h
struct AutoLock{
public:
AutoLock(pthread_mutex_t * lock){
pthread_mutex_lock(lock);
mylock = lock;
}
~AutoLock(void){
pthread_mutex_unlock(mylock);
}
private:
pthread_mutex_t mylock;
}
Code:
void CriticalMethod(void){
AutoLock lock(somelock); //will automatically unlock when it returns
//some critical stuff
if (boolean){
return;
}
//More critical stuff
}
***********************
What exactly would you like to know guitarboy, honoured you came to me 
I learned C first, then taught myself C++. I would recommend just learning C++, most programming is done in C++, and it's a lot easier. It's also a good thing to understand object oriented programming.
Here's some things to understand, in order
Primitive types: int, long, float, char
Scope
methods and functions
pass-by-reference vs pass-by-value
const
Pointers
Objects (classes and structs)
Constructors and destructors
Feel free to IM me about anything
Bookmarks