Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

filemanage Save Error

<< < (2/3) > >>

Alturin:
How about this:


--- Code: ---if(mark_length && f.Write(mark, mark_length) != mark_length)
    return false;

--- End code ---

This way it won't write anything when there's nothing to write?

devilsclaw:
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.

TDragon:

--- Quote from: devilsclaw on March 31, 2007, 08:49:53 am ---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.

--- End quote ---
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.


--- Quote from: TDragon on March 30, 2007, 11:40:17 pm ---So an appropriate solution in this case would probably be to change

--- Code: ---if(f.Write(mark, mark_length) != mark_length)
    return false;

--- End code ---
to

--- Code: ---if (mark_length > 0)
{
    if(f.Write(mark, mark_length) != mark_length)
        return false;
}

--- End code ---

--- End quote ---
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.

devilsclaw:
the original code was doing the line.getchar even though it was not supposed to
it was causing index access errors which is why i even edited it before i got to document it.

Original Code:

--- Code: ---    while (x >= 0 && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')) --x;

--- End code ---

since this is for positions there is always a 0 position so 0 would not cause a index problem.
yet this code did.

the one in the while should be enough from everything i have ever know from coding
but this peice for some reason made me doubt what i knew.. it messed with me man.

New code:

--- Code: ---    if(x >= 0) //have to make sure or it causes errors
    {
       while (x >= 0 && (line.GetChar(x) == ' ' || line.GetChar(x) == '\t')) --x;
    }

--- End code ---

Biplab:

--- Quote from: TDragon on March 31, 2007, 03:19:43 pm ---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.

--- End quote ---

@TDragon

I fully agree with you.

@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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version