Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Noncompliant, since `malloc(0)` is specified to return a unique pointer if it's not `NULL`.

I know I've seen that somewhere, but may I ask what standard you're referring to?

If I recall correctly, this was an archaic stackless microcontroller. The heap support was mostly a marketing claim.



C89: https://port70.net/%7Ensz/c/c89/c89-draft.html

If the size of the space requested is zero, the behavior is implementation-defined; the value returned shall be either a null pointer or a unique pointer.


Isn’t -1 basically 0xffff which is a constant pointer? What am I missinterpreting?


If you call malloc(0) multiple times (without freeing in between) and get -1 each time, then the pointer is not unique.


But do we need a unique pointer or merely a pointer that is disjoint from all objects?


As per the specification, it has to be a unique pointer.

Being tasked to implement a specification typically means having to pass extensive conformance tests and having to answer for instances of noncompliance. You soon learn to follow the spec to the letter, to the best of your abilities, unless you can make a strong case to your management for each specific deviation.


But the letter is non-specific. It doesn't clarify if unique refers to unique when compared to non-zero allocations, or unique when called multiple times.

The C99 standard[1] seems to have worded it more precisely:

If the size of the space requested is zero, the behavior is implementation- defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.

[1]: https://rgambord.github.io/c99-doc/sections/7/20/3/index.htm...


I think that is the problem. I understood unique as „only one“ which means always returns the same. It is imho not clear enough.


It even replaced unique with "disjoint from any other object".

-1 seems to be disjoint from all objects.


Sure, but always returning -1 would not satisfy "the behavior is as if the size were some nonzero value", as that would mean two consecutive calls to malloc(0) would return the same value. Which is not how malloc() with a non-zero size behaves per the previous part of the definition.

Writing a specification is hard...


Hello! I'm sorry to bother you after 3 years of original comment: https://news.ycombinator.com/item?id=30738552

I have two questions:

Could you please specify what have you meant by Fixed Function blocks on Adreno300+? Did you mean regular Rasterizer, DS and vertex assembler by this, or even portions of old FFP functionality just like lighting and etc from ES 1.x?

Because I think there is no need in HW 1.x support, since even Samsung in their FIMG emulated most of classic FFP functionality like combiners through shades.

I haven't investigated SGX53x drivers yet, but I think it was very same, since PVR MBX architecture was mostly abandoned in 2010.

And second question:

Why so many of early qcom android smartphones lacked GPU drivers at all? For example HTC Dream wasn't shipped with gpu drivers, as well as Magic and many Huawei models? For example, Moto droid has GPU drivers from the start.


> Could you please specify what have you meant by Fixed Function blocks on Adreno300+? Did you mean regular Rasterizer, DS and vertex assembler by this, or even portions of old FFP functionality just like lighting and etc from ES 1.x?

This happened almost 20 years ago and I can't even remember what I had for breakfast yesterday, so take everything I say with a grain of salt.

Re. The switch from Adreno 200 to 300. Both had a unified (vertex+pixel) programmable shader unit. They were completely different, with the 200 sporting a VLIW 4+1 vector unit that AMD used at the time, while the 300 was scalar and based on Qualcomm's unreleased QShader core. This made things a lot easier for the poor compiler team.

Sorry, I don't want to go into details about what features were implemented in hardware vs shaders. Every GPU does things a little differently in that regard and there's always some secret sauce. Sometimes features are fully implemented in hardware, sometimes they are fully based on shaders, and often there's a bit of both.

As for Imagination Technologies' SGX 530, which was the successor to PVR MBX, it also had a scalar unified shader unit. I never worked on the MBX, but I was involved in the development of the SGX family back in 2006-2007. Once again, the details of what features were implemented in hardware vs shaders was complicated and I won't get into the secret sauce.

> Why so many of early qcom android smartphones lacked GPU drivers at all? For example HTC Dream wasn't shipped with gpu drivers, as well as Magic and many Huawei models

The question is puzzling to me. The drivers may not be easy to find, but OpenGL would not work without drivers. The HTC Dream shipped with Adreno 130, which I had the unfortunate experience of having to support circa 2008 even though I had not been involved in its development. It felt ancient even at the time, with a super basic vertex shader that we had to manually program in the most rudimentary assembly. Did it even have a pixel shader? God, I can't remember a thing. It did support user clipping planes and stencils. Oh, the nightmares, they haunt me.

Sorry, going back on topic. Yeah, there were drivers for that clunker. They must be hidden somewhere. Please spare a prayer for the souls of the poor bastards who had to work on that abomination. I can't understand how they were able to hold on to their sanity after going through that experience.

Thanks for refreshing my memory. It was Type II fun, for sure.


Huge thanks for your reply! It means a lot for me. I'm tech author and one of my topics are about retro-GPU's, especially rare now like Intel i740, SiS Mirage Graphics, VIA UniChrome aka S3 Savage/Chrome and, of course, 3dfx Voodoo.

> The drivers may not be easy to find, but OpenGL would not work without drivers

It is. Android previously has (and still have) so-called PixelFlinger, which was very fast sw gles 1.1 implementation. Also Android lacked of 2D GPU acceleration prior to 3.0 (partial) and 4.2 (full). Due to lack of GPU drivers, T-Mobile G1 was shipped without any GPU acceleration despite the existence of driver for some other device. What is much more interesting, is that first versions of CyanogenMod had proper driver, i.e libGLES_qcom.so with proper Q3D functions and OpenGL wrappers around them ;)

Also I remember Windows Mobile smartphones from HTC on qcom chipsets which lacked not only d3dm drivers (native for WM), but gles too. For example, HTC Kaiser aka TyTN II. And after one year some other model on same chipset was released with driver, so community just put q3d dlls into Windows folder and got fully working 3D ;)

Yet again, thanks for your reply! It's always interesting to learn something new ;)


> Android previously has (and still have) so-called PixelFlinger, which was very fast sw gles 1.1 implementation

Now that you mention it, that rings a bell. I was very much a product of the fancy new programmable shader era --so much so that I jumped into OpenCL as soon as Apple reached out to GPU vendors.

I have no idea whether any Adreno 120 devices shipped without GPU acceleration enabled. The release date of the HTC Dream around late 2008 is significant, because that means it may have been affected by Qualcomm's acquisition of AMD's handheld IP group, which is where all the Adreno folks were working (including me). It was a chaotic time, with different members of the team joining Qualcomm at different dates, months apart. It's very possible that some releases were "suboptimal" around that time.

> Also I remember Windows Mobile smartphones from HTC on qcom chipsets which lacked not only d3dm drivers (native for WM), but gles too.

IIRC that work was done by one or two ATI old-timers out in Orlando, based on code inherited from ATI. Smart guys, but way under staffed.

Those early years were chaotic in the mobile GPU space. Lots of buggy crappy drivers, lots of buggy crappy hardware. It got better once the teams got bigger and we hired more experienced engineers and managers from desktop GPUs.

Thanks for the questions. Rarely get a chance to talk about that stuff.


This is embedded C where standard abuse is a thing: https://thephd.dev/conformance-should-mean-something-fputc-a...


Well, sure, standards compliance doesn't matter much on such a small device.

Personally I'd be less worried about uniqueness and more worried about alignment. An address of -1 would violate alignment requirements on most modern targets. But that may have been fine on the target in question; older microcontrollers tended to not have any hardware-level alignment requirements, and the C implementation could have treated all types as having alignment 1.


Null is not a unique pointer, it's a contant like -1

It returns multiple types of null pointer


The spec says that malloc(0) shall return "either a null pointer or a unique pointer". If it's null, it doesn't have to be unique.


(you duped your comment under the other subthread)

From C89, §7.10.3 "Memory management functions":

> If the size of the space requested is > zero, the behavior is implementation-defined; the value returned shall be either a null pointer or a > unique pointer.

The wording is different for C99 and POSIX, but I went back as far as possible (despite the poor source material; unlike later standards C89 is only accessible in scans and bad OCR, and also has catastrophic numbering differences). K&R C specifies nothing (it's often quite useless; people didn't actually write against K&R C but against the common subset of extensions of platforms they cared about), but its example implementation adds a block header without checking for 0 so it ends up doing the "unique non-NULL pointer" thing.


I meant to ask both people the same question.

I wouldn't be surprised if Win3.1-looking tool chain had not implemented c89, though I'm certain it wasn't c99 compliant, which only requires that the pointer is a disjoint from any object, not unique.

It's strange that the standard has relaxed over time.


Presumably the ANSI C standard or one of the later editions? They also cover the standard library as well as the language. (Presumably the bit about "Each such allocation shall yield a pointer to an object disjoint from any other object." if the random C99 draft I found via google is accurate to the final standard - I suppose you might question if this special use is technically an allocation of course).

Of course, microcontrollers and the like can have somewhat eccentric implementations of languages of thing and perhaps aren't strictly compliant, and frankly even standard compliant stuff like "int can be 16 bits" might surprise some code that doesn't expect it.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: