I have some newbie questions
Hello everyone!
I am an experienced Pascal programmer but I'm new to C++. I'm trying to avoid asking stupid questions but every book, tutorial, FAQ, etc I have found always assumes that I know this stuff. Please help me if you can!
1. What does the underscore (_) and double underscore (__) in front of a function and/or variable name mean?
2. What is the difference (if any) between these two lines of code? I'm specifically talking about the placement of the *
int Read(unsigned char *buff);
int Read(unsigned char* buff);
3. In the following function if the IF condition evaluates to true will that cause a memory leak with temp?
int FileChunk::Read(unsigned char *buff,int maxNum)
{
DWORD numRead = 0;
//allocate a buffer big enough to hold the users data plus the header
unsigned char *temp = new unsigned char[maxNum + sizeof(cid)];
//read in the specified number of bytes
if (numRead = GenericFile::Read(temp,maxNum + sizeof(cid)))
{
... //misc code
//return the number of bytes read
return numRead;
}
delete[] temp;
//return false
return 0;
}
I would appreciate any help you can provide. Thanks!
Myra Mains
Re: I have some newbie questions
Welcome aboard, Myra...
>>1. What does the underscore (_) and double underscore (__) in front of a function and/or variable name mean?
It doesn't actually mean anything. Just a naming convention.
>>2. What is the difference (if any) between these two lines of code? I'm specifically talking about the placement of the *
>>int Read(unsigned char *buff);
>>int Read(unsigned char* buff);
They mean the same thing. Both mean that the function Read takes a param that is an unsigned char pointer called buff. The placement of the * is (more or less) a matter of your own style.
Re: I have some newbie questions
Originally posted by Myra Mains
Quote:
1. What does the underscore (_) and double underscore (__) in front of a function and/or variable name mean?
Can't say, never seen that.
Quote:
2. What is the difference (if any) between these two lines of code? I'm specifically talking about the placement of the *
int Read(unsigned char *buff);
int Read(unsigned char* buff);
No difference, matter of preference.
Quote:
3. In the following function if the IF condition evaluates to true will that cause a memory leak with temp?
int FileChunk::Read(unsigned char *buff,int maxNum)
{
DWORD numRead = 0;
//allocate a buffer big enough to hold the users data plus the header
unsigned char *temp = new unsigned char[maxNum + sizeof(cid)];
//read in the specified number of bytes
if (numRead = GenericFile::Read(temp,maxNum + sizeof(cid)))
{
... //misc code
//return the number of bytes read
return numRead;
}
delete[] temp;
//return false
return 0;
}
Not for the reason you state, but you need another closing brace after delete[] temp.