brianfen
Exactly! That's why once virtual memory is allocated, malloc() is allowed to consider the operation successful. The standard does not care at all whether it is virtual memory allocation or physical memory allocation. It is completely unspecified in the standard what sort of memory must be allocated. So no spec in the standard is being violated by returning non-null pointer for virtual memory allocation.
Section 7.22.3.1:
The order and contiguity of storage allocated by successive calls to the aligned_alloc, calloc, malloc, and realloc functions is unspecified. The pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to a pointer to any type of object with a fundamental alignment requirement and then used to access such an object or an array of such objects in the space allocated (until the space is explicitly deallocated). The lifetime of an allocated object extends from the allocation until the deallocation. Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer is returned. 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.
Section 7.22.3.4:
The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate.
So once again, can you cite the exact section number from the standard that you think is being violated here?
At the risk of being downvoted, I feel compelled to offer a foreigner's perspective here. As a foreigner who has lived in Bangalore, Mysore, Hyderabad, and Mumbai for 2 to 6 months many times, I have to agree with the other commenter that I did not find a functioning society. Things I saw during my visits:
- Cops refusing to file a report after a theft.
- No medical or police help during accidents. It's up to the untrained passers-by to administer some form of first aid and take an injured person to medical care facility.
- Motorcycle riders driving on sidewalks.
- Cars driving on the wrong side of the road.
- Drivers not yielding to pedestrians at crosswalks.
- Tuk-tuks refusing rides in gross violation of government regulations.
- Damage and pilferage of public property in Indian Railways.
- Eunuchs extorting money from unsuspecting people in broad daylight.
Some of these things are not exceptions but the rule. This does not consititute a functioning society per my expectations and standard of living. This is a total breakdown of law, order, civility, decency, and courtesy in society.