Tuesday, 16 November 2010
Sunday, 14 November 2010
Thursday, 11 November 2010
Sneaky use of sequence points in c++
i've found a very interesting corner case where fiddly knowledge of
sequence points and STL are used.
apparently it's not possible to use remove_if on associate arrays but
this didn't stop me trying for a good 30 mins before i discovered this
workaround:
There's no evidence in the answer, but it's apparent after digging
through the numerous overloads and associated nastiness that its
apparently excusable simplicity comes down to sneaky use of sequence
points.
http://www.cplusplus.com/reference/algorithm/remove_if/
http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap/800984#800984
sequence points and STL are used.
apparently it's not possible to use remove_if on associate arrays but
this didn't stop me trying for a good 30 mins before i discovered this
workaround:
for(; iter != endIter; )
{
if(Some Condition)
{
// is it safe ?
aMap.erase(iter++);
}
else
{
++iter;
}
}
There's no evidence in the answer, but it's apparent after digging
through the numerous overloads and associated nastiness that its
apparently excusable simplicity comes down to sneaky use of sequence
points.
http://www.cplusplus.com/reference/algorithm/remove_if/
http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap/800984#800984
Silly programming errors
Here's a list of silly programming mistakes I've made recently with the appropriate line highlighted. You can clearly see from the context given that it was not intended, but you must look carefully.
This one was caught by valgrind, about 6 frames deeper as being uninitialized:
This one typically gives a compiler warning. However this one I found after my filesystem started gaining free space when I copied to it.
This one was the hardest to find. I did not even know it was the cause of the problem. In Windows there is a special form of "stat" used in their equivalent to "readdir". The erroneous file sizes would only cause errors in applications that depended on the readdir() form, such as the builtin Windows explorer and image viewer.
Are these the kind of "problems" with using C, and allegedly to a lesser degree (but still present) C++? The general opinion is that these are typing errors, but languages like Python would never pick them up, and in statically typed languages the use of primitive types would still prevent any checks by the compiler.
This one was caught by valgrind, about 6 frames deeper as being uninitialized:
struct CpfsTime ct[2]; timespec_cpfstime(&tv[0], &ct[0]); timespec_cpfstime(&tv[0], &ct[0]);
This one typically gives a compiler warning. However this one I found after my filesystem started gaining free space when I copied to it.
if (g_cpfs->freeblks = -1) {
g_cpfs->freeblks = bitmap_avail_raw();
}
This one was the hardest to find. I did not even know it was the cause of the problem. In Windows there is a special form of "stat" used in their equivalent to "readdir". The erroneous file sizes would only cause errors in applications that depended on the readdir() form, such as the builtin Windows explorer and image viewer.
split_to_DWORDs(cpfsStat.size, to.nFileIndexLow, to.nFileSizeHigh); to.nNumberOfLinks = cpfsStat.nlink; split_to_DWORDs(cpfsStat.ino, to.nFileIndexLow, to.nFileIndexHigh);
Are these the kind of "problems" with using C, and allegedly to a lesser degree (but still present) C++? The general opinion is that these are typing errors, but languages like Python would never pick them up, and in statically typed languages the use of primitive types would still prevent any checks by the compiler.
Saturday, 30 October 2010
Sunday, 24 October 2010
Ubuntu Maverick 10.10
Pros
- The new font is great.
Cons
- Booting is not clean on all hardware.
- Default themes still have contrast issues.
- Many packages are unstable, or have conflicts.
- Unity is completely broken. It has terrible performance and no functionality at all.
This is not good for an Ubuntu release. 5/10.
Saturday, 3 July 2010
Tkinter
Pros
- Ships with Python.
- Also has C and Tcl bindings.
- Not necessarily packaged with Python.
- Looks like arse.
- Nobody has tried writing doco for it in 5 years.
- Nobody has ever written complete documentation for it.
- It's behind the mainstream GUI toolkits by about 15 years.
- The bindings were written in around 1997, and probably only stick around because they're low maintenance, and picking another toolkit would invoke a holy war.
- Errors, and invalid geometry configurations don't always throw exceptions, and may cause infinite loops.
Subscribe to:
Posts (Atom)