News for hackers. Stuff that matters.
Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by adamnemecek on Saturday June 14, 2014 @02:52AM (#7892243)
'But on BOTH PLATFORMS they call the same line of code -> BzUiUtil::PauseBackup();'

That's some funky C code you got there Brian.

Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by mtdewcmu on Saturday June 14, 2014 @05:05AM (#7892408)
I thought that, too, when I saw that example, clearly in C++, after about 100 mentions of 'C'.

I've encountered programmers that habitually refer to C++ and ObjectiveC as C. I suspect he has that habit.

Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by brianwski on Monday June 16, 2014 @10:15PM (#7902527)
Original author here:

No, we use 'C' and 'C++' on Windows PCs, and we use 'C' and 'C++' and 'Objective C' on the Macintosh. Objective C can call into 'C' libraries just fine on the Macintosh. Objective C can also call into C++ just fine on the Macintosh.

The distinctions are very important to us. :-) Objective C cannot compile on Linux or Windows, but 'C' and 'C++' can compile on all three platforms (Macintosh, Linux, and Windows) using the default development environments on all three platforms (GCC on Linux, Xcode on Macintosh, Visual Studio on Windows).

Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by Joeri on Saturday June 14, 2014 @04:31AM (#7892370)
Pretend he wrote bzuiutil_pause_backup(); and the rest of the advice holds up.
Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by brianwski on Monday June 16, 2014 @10:29PM (#7902569)
Original author here. Exactly, thank you! I thought everybody knew 'C' and C++ both, and specifically that:

1) 'C' is the most basic, it only has functions. A function call looks like "bzuiutil_pause_backup();"

2) 'C++' is a super set of 'C' and if you want to group several static functions together, you can put several static functions in one class. This defines scope, and also allows programmers to find where the function is written, in this case "BzUiUtil::PauseBackup()" means that there is a 'C++' class called BzUiUtil and it has a static function with EXACTLY the same contents as the 'C' version has inside "bzuiutil_pause_backup();"

At Backblaze, we tend to void writing 'C' code in favor of 'C' code in static C++ wrappers as described in point "2" above. There isn't any downside as long as all of your compilers on all platforms are C++ compilers anyway. I honestly didn't know a pure 'C' compiler still exists. Specifically, Microsoft Visual Studio does both seamlessly. On the Macintosh Xcode does both seamlessly. On Debian Linux (the flavor we use most and is also the slowest to adopt anything) the g++ compiler ships for free on every linux box that does both seamlessly.

Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by foxhill on Saturday June 14, 2014 @11:53AM (#7892994)
the stuff he talks about applies to C and C++ - i think we can forgive that faux pas :)
Re:Brian's Rules for Writing Cross Platform 'C' Code (2008) by chj on Saturday June 14, 2014 @04:31AM (#7892371)
The code examples are all C++, but from what I understand the rules apply to C as well.