C versions

So, I was working on the position independence stuff and thinking about how I’ve currently implemented multi-segment support – I’m comparing pointers in different allocations. This is not legit, but normally it works… which doesn’t fill me with joy.

While looking over how this can fail (I was thinking about memory range address extensions on 32-bit platforms) I came across some posts about the type of the result of subtracting a void pointer from a void pointer.

It’s a ptrdiff_t, of course…

…except it’s not.

Standard C does not support subtracting void pointers from void pointers, because the type is unknown.

GCC lets you do this as an extention – treats the pointers as pointers to unsigned char.

I then after a bit realised I was getting a -lot- of extras from using -std=gnu89 rather than -std=c89, which I’d done just to get C++ style comments.

So wrote a script, converted all C++ style comments to C comments, and changed to c99 with -pedantic-warnings.

Keeeeeeeeeerunch.

“Type long long not supported”.

Bloody right too – “long long” didn’t turn up in the Standard until C99.

It’s a GCC extension prior to C99.

My problem is I’ve had to support Windows, and MS stopped supporting C decades ago, so they’re still C89 – and in fact I’ve been using a platform extension there too. Until now I’ve not worried very much about the later C versions – I’ve got the specs, I need to sit down and read them through. I’d rather have a good book than the spec though – I originally learned C from “The C Book”, which is excellent. (But now I’ve got some time, yes, I’ll finally read through them all. It’s a shame in a way – I’d like to only have to know one version of C, but because of Windows, I need to hang on to remembering C89 – this is actually why I’ve not moved on yet.)

So anyways embarrassement aside, C99 is only really properly supported until GCC 4.5.0.

This is a bit of an interesting problem.

GCC doesn’t really start to compile for non x86/x86_64 platforms until about 4.5.4 (and 4.7.3 for ARM), so that’s okay.

However, I have GCC 4.20, 4.2.2 and 4.2.4 compiled for x86_64 – so if I wanted to support them, I’d need to use gnu89.

So…

All in all, looks like I need to use -std=c99.

This is fine for non-Windows platforms – it will enable long long, and I won’t use any other functionality, so I can still compile on Windows (since the porting layer defines will mean I use the platform extention on Windows for 64 bit types).

Ironically, of course, this means the work I did to replace C++ style comments with C style comments is now not necessary =-)