Posts made by pure
-
RE: C code sample for interview
@Steve The Cynic said:
Inconsistent behaviour between platforms is hardly a surprise. Nobody has mentioned the reason, though. The words you are looking for are "undefined behaviour" and as you should all know that means "demons fly out of your nose" or "millions die in a nuclear fireball", although the latter applies only when the code is running on a DeathStation 9000.
Hence why inttypes.h exists. From the (linux) manpage:
APPLICATION USAGE The purpose of <inttypes.h> is to provide a set of integer types whose definitions are consistent across machines and independent of operating systems and other implementation idiosyncrasies. It defines, via typedef, integer types of various sizes. Implementations are free to typedef them as ISO C standard integer types or extensions that they support. Consistent use of this header will greatly increase the portability of applications across platforms.
-
RE: C code sample for interview
I think the world would be a better place if it used PRIx64 from inttypes.h
#include <stdio.h> #include <inttypes.h>
int main (int argc , char ** argv)
{
uint64_t a = 0xC0FFEE;
uint64_t b = 0xBADBEEF;printf("a: %" PRIx64 "\nb: %" PRIx64 "\n", a, b); return 0;
}
Output:
a: c0ffee b: badbeef
or did i miss something?
-
RE: The Redirector
@snoofle said:
If we hadn't run this test, it would've gotten released to production with everything hanging off of a local copy of unreleased software running on a roaming laptop.
really? The production is on the same network as the guy's development laptop?!
Surely not.
-
RE: Subversion comments
@Rick said:
@pure said:
One word - nondeterminism.
At least, I think that is a word.
Anyway, queue someone bringing up Why Threads are a Bad Idea (for most purposes)
That was written in 1996 when using anything but a single processor was unusual. It is 17 years later. Move on.
No doubt. I particularly like the way it refers to anyone who knows a bit of C++ as a "Wizard". And more ludicrously, that people who know C++ somehow greater than people who "only" know C.
It's right about VB programmers, though, right ?!
Seriously, though, in my experience most developers even now don't know how to write reentrant code or avoid deadlocks (or, worse, go so far out of their way to remove deadlocks, that the app spends 90% of its time fiddling with locks or waiting for them). And this certainly doesn't just apply to youngsters.
There's a fairly famous attempt to speed up a part of our application with threads. The release note claimed something ludicrous like 1000x better performance. Lots of work was done over lots of man-months. The result? Stuff like this:
void GotSomeData(const char * someData)
{
if (Logger.IsLoggingLevelEnabled(1))
{
Logger.write("did some stuff with: %s", someData);
}// pass the data on to the "main" thread messageQueueForData.Put(someData);
}
Naturally, this was executed in a whole bunch of threads which sat waiting for "someData" to pass around. Anyway, you've probably guessed that the Logger.IsLoggingLevelEnabled method is syncronised (i.e. implemented as GetLock(); DoStuff();. ReleaseLock(); or whatever), so the performance of the system was: worse
-
RE: Subversion comments
One word - nondeterminism.
At least, I think that is a word.
Anyway, queue someone bringing up Why Threads are a Bad Idea (for most purposes)
-
RE: The tale of min and max.
I should probably say that I wasn't having a go at Microsoft particularly. The decision to do such a thing in any code (particularly header files) is WTF and it would be WTF in any API or set of headers. This thread happened to be talking about a Microsoft package with which I'm not familiar.
-
RE: The tale of min and max.
The options aren't the WTF. The #defines in Microsoft's standard headers are the WTFs.
The C++ FAQ Lite is great fun with regards macros. For example:
@C++ FAQ Lite said:
39.5 What should be done with macros that have multiple lines?
Answer: Choke, gag, cough. Macros are evil in 4 different ways: evil#1, evil#2, evil#3, and evil#4. Kill them all!! (Just kidding.)
.... answer ....
-
RE: Are people REALLY this dumb?
O man. That guy is from like 5 minutes from where I grew up.
Seriously, my address was...
-
RE: Mixed-endianness
@Mcoder said:
Hardly anybody pass a shape file through a bare network stream, people pass files thourgh TCP or UDP.
Troll?
-
RE: Mixed-endianness
@Mcoder said:
@pure said:
I think I can hazard a guess...
Classically, "network" endianness is "big endian." I think this makes most sense when reading a stream byte-by-byte off a socket. In Shapefile, the big-endian values at the beginning (file code and length, record number and length) are fairly common in messages passed over a network (e.g. message type + length equivalent, field type + length, etc.). This may be why they are big-endian.
As old they are, I don't think shape files preceed TCP.
I once glanced at a hedge. What's your point?
-
RE: Mixed-endianness
I think I can hazard a guess...
Classically, "network" endianness is "big endian." I think this makes most sense when reading a stream byte-by-byte off a socket. In Shapefile, the big-endian values at the beginning (file code and length, record number and length) are fairly common in messages passed over a network (e.g. message type + length equivalent, field type + length, etc.). This may be why they are big-endian.
The rest of the values are probably little-endian because x86 systems are little endian and therefore don't require a "flip" from the actual data read (or received in network terms).
Like I said it's just a guess, but it seems plausible. You read 28 bytes off the socket (out of the file), ntohl() the first 4 to get the message code, then ntohl() the 25th-28th and multiply by 2 to get the file length in bytes. then read that file length (minus header) by casting the remaining values directly, to say int32_t (assuming you're on x86, otherwise flipping them).
It seems dumb, but the only explanation I can think of...
-
RE: Conversation with a DBA
@snoofle said:
The email specified svn version number, mantis ticket # and referred to the attached scripts, explicitly by name and in the order they should be run.
Well. There's not a huge amount more you can do.
@snoofle said:
These guys are just lazy idiots.
Lazy? Inability to follow simple instructions sounds more like incompetence to me!
-
RE: Conversation with a DBA
@Quango said:
You obviously forgot to end your email with a GO statement, so the email did not commit.
Brilliant.
But TRWTF is sending scripts to run on production database via email and not having a well-defined way of referring to each "version" of the script...
-
RE: Does anyone remember when I said I wished developers couldn't use Copy-Paste?
Have you tried rebooting windows to fix your clipboard? Clipboard deadlock is the bane of anyone who uses windows and:
- uses virtual PC or VMWare or anything
- uses a windows X server
- uses RDP or other remote desktop stuff (such as VNC)
I do all of these things and the windows clipboard deadlocks roughly once a week forcing a reboot.
Anyway, my guess is that it is your setup, not OSX that is the problem here.
-
RE: Sometimes you have to admire the ingenuity
+1 : genuine, eyes-wide, shout-out-loud WTF.
I would say this would be good front-page material, but it's simply better than that.
-
RE: Finally nada
Wait, noone mentioned on error goto (which is what it is more like)?
Like (err...)
Sub Marine ()
on error goto Finally
' do some stuff (aka try)
Finally:
'nada
End
Let the flamewar continue...
-
RE: Manually
@speakerphone dude - yes. It is staggering how often the computer forgets people's passwords over the weekend.
-
RE: Manually
@snoofle said:
int false = 0 compiles and runs
It does in C of course because &false in that context means "the address of the (integer) variable 'false'" which can be dereferenced (by memcpy) to 0.
However, in (forte) C++, where false is a reserved word:
>CC -o false false.cc
"false.cc", line 7: Error: The "&" operator can only be applied to a variable or other l-value.From:
1 : #include <iostream>
2 : int main(int argc, char **argv) {
3 : int x[3];
4 : memset(x, 0, sizeof(x));
5 :
6 : memset(x + 1, false, sizeof(false));
7 : memcpy(x, &false, sizeof(false));
8 : std::cout << "x[0]="
9 : << x[0]
10: << " x[1]="
11: << x[1]
12: << " x[2]="
13: << x[2];
14:
15: return 0;
16:} -
RE: Manually
@rstinejr said:
I work with a way senior developer, friend of my boss, who is always saying things like "Perforce isn't working" or "Java is returning the wrong time value" or "MySQL has locked the table"; when he's especially egregious I put the headphones on and crank up music to keep from strangling him.
When one is developing new software, or solutions, and one hits an issue, one has two choices:
- Blame your new untested code, or integration that you've just put together
- Blame the 10-year-old library code, or released software, which you're using and 1000s of other people are using successfully.
- Blame your new untested code, or integration that you've just put together
-
RE: Programmers trying to talk to non-programmers without getting sidetracked by trivialities? IMPOSSIBLE!
@blakeyrat said:
I think there are some people who will never 100% get pointers. I also think I'm one of them.
All the more reason to toss out our shitty old languages from crap-town which have them.
One of the more amusing things i heard a friend say once was "Oh, C++? I don't get that, you know, with all the pointers and all. I just use Java. It doesn't have pointers."
Now I'm not trying to get into a debate over which is "better" (or the perhaps pertinent point -ahem- about memory management), but all "references" in java are just pointers, right. You copy or compare them (with trival operations) and they behave like C pointers. You clone() or compare() them and they behave like objects.
After explaining this, the friend in question now gets pointers. I don't know if he gets manual memory management, but that's another lecture.
-
RE: Programmers trying to talk to non-programmers without getting sidetracked by trivialities? IMPOSSIBLE!
@some_idiot_on_other_forum said:
I totally agree with TriPolar. I've been programming in BASIC since the late 70s, and was totally thrown by the syntax of the OP's example.
TRWTF right there. This dude has been programming BASIC for over 30 years and still can't read other languages. Someone buy him this.
Actually, wait. TRWTF is simpler - he's been programming BASIC over 30 years.
-
RE: It's in svn so it's ok
@Someone You Know said:
@Anonymouse said:
I always get Puff Daddy and Skrillex mixed up.@PJH said:
@SEMI-HYBRID code said:
I always get Puffix and Srefix mixed up.suffix
Prefix, Shirley?When it is music, i think it's called a mashup...
-
RE: Better just check...
@DescentJS said:
@pure said:
This is clearly to protect against concurrency issues. The value of tmp could change between assigment and comparison. It's concurrency 101!
Yep, this is the way I always do my concurrency checking.
Some people, when confronted with a problem think, “I know, I’ll use threads”, and then two they hav erpoblesms.
-
RE: Better just check...
This is clearly to protect against concurrency issues. The value of tmp could change between assigment and comparison. It's concurrency 101!
-
RE: Pointer or false?
Isn't NULL defined as 0 in C++? Isn't false also defined as 0 when cast to an integer (or pointer)?
Not saying it isn't retarded tho.
-
RE: If certain tech companies produced carpentry tools...
You forgot to mention that xcode-hammer can only be used for roughly 1 hour at a time before having to be put down and picked up again. And that the time shortens with each new release.
-
RE: Representative line
what's sad is that fieldHasChanged is actually a macro. the only side-effect of which being that this critical component crashes if you don't call another macro, which we'll call initialiseField() previously. sigh.
-
Representative line
I work on reasonably large cog in a huge system of pipes, cogs and magic. Sometimes, you see total complete WTFs that are worthy of the main page. Sometimes you're just baffled. Sometime, you see this:
// <snip about 20 lines of comment, justifying why the TYPE and FLAG changing are important>
if (fieldHasChanged (FieldDef::TYPE) || fieldHasChanged(FldDef::FLAG) || 1)Naturally, the justification doesn't include why it is a tautology.
I checked the history, and this line was witten as-is along with the 20-line comment and the tautology in the first revision. In 2004.
I know this isn't the worst WTF in the world, but the actual block the "if" wraps contains a bunch of dubious uses of exceptions, macros and the inner-system anti-pattern. This line just summed it up for me.
-
Bumblebee
I think this is why testing is important:
https://github.com/MrMEEE/bumblebee/commit/a047be85247755cdbe0acce6#diff-1
-
RE: This is just so wrong...
http://www.webking.com/computer-services/websites.htm
"<font color="#004080" face="Times New Roman">While waiting for the graphics on this page to load, there are some important things you should know about the effective design of WebSites..."</font>
Legendary.