GCC left shift overflow

Short answer: the Intel processor masks the shift count to 5 bits (maximum 31). In other words, the shift actually performed is 32 & 31, which is 0 (no change). The same result appears using gcc on a Linux 32-bit PC. I assembled a shorter version of this program because I was puzzled by why … Read more

How can I programmatically change the background in Mac OS X?

From python, if you have appscript installed (sudo easy_install appscript), you can simply do from appscript import app, mactypes app(‘Finder’).desktop_picture.set(mactypes.File(‘/your/filename.jpg’)) Otherwise, this applescript will change the desktop background tell application “Finder” set desktop picture to POSIX file “/your/filename.jpg” end tell You can run it from the command line using osascript, or from Python using something … Read more

Mac Terminal – ‘pointer being freed was not allocated’ error when opening terminal

It looks like you don’t have the right permissions on the /usr/bin directory. Solution for OS X 10.11 (El Capitan) and later: Install Onyx 3.1.3 app (Free analog of Disk Utility) Choose ‘Maintenance’ -> ‘Permissions’ -> ‘Execute’. Solution for older versions of OS X: Open ‘Disk Utility’ app -> Press ‘Repair Disk Permissions’. It will … Read more

x86 Assembly on a Mac

After installing any version of Xcode targeting Intel-based Macs, you should be able to write assembly code. Xcode is a suite of tools, only one of which is the IDE, so you don’t have to use it if you don’t want to. (That said, if there are specific things you find clunky, please file a … Read more