if(f.Write(mark, mark_length) != mark_length)
return false;
if(mark_length)
{
f.Write(mark, mark_length);
}
char* mark = NULL;
size_t mark_length = 0;
if (bom)
{
switch (encoding)
{
case wxFONTENCODING_UTF8:
mark = "\xEF\xBB\xBF";
mark_length = 3;
break;
case wxFONTENCODING_UTF16BE:
mark = "\xFE\xFF";
mark_length = 2;
break;
case wxFONTENCODING_UTF16LE:
mark = "\xFF\xFE";
mark_length = 2;
break;
case wxFONTENCODING_UTF32BE:
mark = "\x00\x00\xFE\xFF";
mark_length = 4;
break;
case wxFONTENCODING_UTF32LE:
mark = "\xFF\xFE\x00\x00";
mark_length = 4;
break;
case wxFONTENCODING_SYSTEM:
default:
break;
}
}
if(f.Write(mark, mark_length) != mark_length)
return false;
if(f.Write(mark, mark_length) != mark_length)
return false;
if (mark_length > 0)
{
if(f.Write(mark, mark_length) != mark_length)
return false;
}
wxFile::Write
size_t Write(const void* buffer, wxFileOffset count)
Writes the specified number of bytes from a buffer.
Parameters:
buffer - A buffer containing the data.
count - The number of bytes to write.
Return value:
the number of bytes actually written
if (mark_length > 0)
{
if(!f.Write(mark, mark_length) )
return false;
}
so im guessing the code should look like thisThis incorrectly assumes that any nonzero value means the write was successful. wxFile::Write might return a number greater than 0 but less than mark_length. The original code would correctly detect, in that case, that the write wasn't fully successful, and return false.Codeif (mark_length > 0)
{
if(!f.Write(mark, mark_length) )
return false;
}
if(mark_length && f.Write(mark, mark_length) != mark_length)
return false;
i found each compiler handles certain things differently.This is not the case. Both compilers implement an important part of the C++ language called "short circuit evaluation" or "lazy evaluation". If the value of the first operand of a logical operator (such as && or ||) can determine the result (i.e. "false" for &&, "true" for ||), the second operand is not evaluated. This is true for every modern compiler including both MSVC and GCC.
bool hello = true;
wxFile f("myfile");
i know the MS compiler if you do a if statement if(!hello && f.write(_("2"),2) > 0)
since the hello is true it f.write does not get ran..
but the other day with the g++ for some reason there was a if statement that was like that and the code still got ran.
So an appropriate solution in this case would probably be to changeApparently there's some part of my suggested code that you think is broken or incorrect; I assure you it's not.Codetoif(f.Write(mark, mark_length) != mark_length)
return false;Codeif (mark_length > 0)
{
if(f.Write(mark, mark_length) != mark_length)
return false;
}
while (x >= 0 && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')) --x;
if(x >= 0) //have to make sure or it causes errors
{
while (x >= 0 && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')) --x;
}
With all due respect:
It's clear you're not familiar with the "ins and outs" of the C++ language. You'll end up writing a lot of code with good intentions, and then running into a lot of problems that, to more experienced developers, are simple mistakes simply fixed. I make no claims to speak for the official Code::Blocks developers, but I imagine it may be somewhat annoying to see the Code::Blocks Development forum filled with posts that have less to do with getting serious work done on C::B and more to do with you figuring out how C++ works.
Apparently there's some part of my suggested code that you think is broken or incorrect; I assure you it's not.
With all due respect:
It's clear you're not familiar with the "ins and outs" of the C++ language. You'll end up writing a lot of code with good intentions, and then running into a lot of problems that, to more experienced developers, are simple mistakes simply fixed. I make no claims to speak for the official Code::Blocks developers, but I imagine it may be somewhat annoying to see the Code::Blocks Development forum filled with posts that have less to do with getting serious work done on C::B and more to do with you figuring out how C++ works.
i found each compiler handles certain things differently.
bool hello = true;
wxFile f("myfile");
i know the MS compiler if you do a if statement if(!hello && f.write(_("2"),2) > 0)
since the hello is true it f.write does not get ran..
but the other day with the g++ for some reason there was a if statement that was like that and the code still got ran.
I dont know why and maybe i did something wronge but im pretty sure it was because how g++ compiled it.
so if f.write gets ran and it should not it might error.
but then again i might be wronge.. i will try to reproduce the probem i was running into and post it here.
How about this:Codeif(mark_length && f.Write(mark, mark_length) != mark_length)
return false;
This way it won't write anything when there's nothing to write?
@devil....
Please don't fill up the Developer forum with your crappy patches. I've tested some of your patches and they break more than they fix.
IMO, you are trying to show that Code::Blocks's 0.25 million lines of code is mere crap and is broken.
The problem is you are reading few lines of code and making 100 lines of comments. Try to understand why that piece of code is there and if you remove it what will happen to the remaining code.
I'm sorry if my reply seems harsh. But I can't stop writing this. I'm sick of your posts.
My suggestion, if you find any bugs, report it in Berlios. If you have fixed that, post it in Berlios. We'll test it and apply.
Don't use this forum to post each and every piece of code you write.
In short, Please Don't Pollute the Forum.
if the below comment was aimed at me it was missplaced since if you read the post i alread agreed with you.My mistake. This comment was unnecessary.Apparently there's some part of my suggested code that you think is broken or incorrect; I assure you it's not.
With all due respect:This one, I still stand by.
It's clear you're not familiar with the "ins and outs" of the C++ language. You'll end up writing a lot of code with good intentions, and then running into a lot of problems that, to more experienced developers, are simple mistakes simply fixed. I make no claims to speak for the official Code::Blocks developers, but I imagine it may be somewhat annoying to see the Code::Blocks Development forum filled with posts that have less to do with getting serious work done on C::B and more to do with you figuring out how C++ works.
http://forums.codeblocks.org/index.php/topic,1519.0.html
as for the other stuff i was just trying to be personalble and most of it i was asking for input.
... but I imagine it may be somewhat annoying to see the Code::Blocks Development forum filled with posts that have less to do with getting serious work done on C::B and more to do with you figuring out how C++ works.
the original code was doing the line.getchar even though it was not supposed toIt seems you really don't understand what is intended, nor what is actually happening (because your statement is wrong).