|
megaadam wrote: Since the result of malloc(wanted) for wanted==0 is undefined (across platforms)
When discussing Standards, we must use the correct terms. The C Standard differentiates between Undefined Behaviour and Implementation Defined Behaviour.
Undefined Behaviour means precisely that. The implementation is within its rights to do anything - format your disk, set fire to your cat, or make demons fly out of your nose. Avoid at all costs!
Implementation-Defined Behaviour means that the implementation may choose between a few different implementations listed in the Standard, the choice being documented in those manuals that nobody ever reads ( ). The behaviour of malloc(0) is one of these. One should attempt to avoid these in the interest of writing portable code, but they are sometimes necessary.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
While what you say is technically correct I daresay that if you replace "undefined (across plattforms)" in my statement
With any of:
- implementation defined
- unknown, by programmer [due to unspecified implementation]
- any
you still should check wanted==0 [and avoid the syscall if true], especially if you want your code to be portable.
And I never said "Undefined Behaviour" I said "undefined (across platforms)". Still, from a strict perspective that was a slightly sloppy wording, yes.
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
We like to create wrappers for most standard APIs. Mostly to make it easier to swap implementations without impacting application code.
Consider a higher level allocation concept where you
MyThing* next = allocMyThing(…);
You could have a static (or dynamic) MyThing that covers the case correctly and cleanly where the malloc(0) case crops up.
Different types will need different implementations to correctly avoid malloc(0).
IF you stick with allowing malloc(0), try some more band aids…
If running in test:
it might be best to assert and crash the program. What condition is trying to malloc(0)? Fix it.
For non-test:
It seems like your wrapper method could check for 0 size and return a (global?) static pointer to a zeroed block of memory.
You would get a safe pointer back, but like other posters have pointed out, you should never really dereference a pointer to nothing. If this is cast to char*, you would have a in effect a zero length string.
If you use a global static, the caller could check against the returned value for an exact pointer match, but again it seems it would be best to never call malloc(0).
If it is new code, avoid the malloc(0) calls.
If this legacy code, good luck!
Edit
If you use the static, your wrapper for free() will need to check for a match and skip the actual call to free().
If you wrap malloc, you need to wrap the inverse API as well!
|
|
|
|
|
All excellent advise. Some which I already follow. Thanks, appreciate it.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 549 4/6
⬛⬛⬛🟨⬛
⬛⬛🟩⬛🟨
🟩🟩🟩⬛⬛
🟩🟩🟩🟩🟩
Back to normal!
|
|
|
|
|
Wordle 549 3/6
⬜🟨🟩⬜⬜
⬜🟩🟩⬜🟩
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 4/6
⬜🟨⬜⬜⬜
⬜⬜🟩🟨⬜
🟨🟨🟩⬜⬜
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 3/6
⬜⬜🟩🟨⬜
⬜⬜🟨🟨🟨
🟩🟩🟩🟩🟩
Yay starters!
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Wordle 549 5/6
🟨⬜🟩⬜⬜
⬜⬜🟩⬜⬜
⬜🟨🟩⬜⬜
⬜🟩🟩🟩⬜
🟩🟩🟩🟩🟩
It was the only possible word with my letters and I didn't see it (looked it up)
|
|
|
|
|
Wordle 549 5/6
⬛⬛🟨⬛⬛
⬛🟨⬛⬛⬛
⬛⬛⬛⬛🟨
⬛🟨🟩⬛🟨
🟩🟩🟩🟩🟩
GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
Wordle 549 2/6
⬜⬜🟩🟩🟩
🟩🟩🟩🟩🟩
Not bad started strong
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Wordle 549 3/6
⬜🟨⬜⬜⬜
🟨🟨🟨🟨⬜
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
That was a very good second guess
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
The first one covered three vowels, none of which came up - so I wanted a word with at least one of the other two. Given the three that aren't there, the letter I did get in the wrong place was very unlikely to be at the start or end, so middle was the best guess. I was lucky with the four of 'em, and it only left me one choice for the third guess.
(Trying not to give spoilers, here!)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And succeeding
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
⬜🟨⬜⬜⬜
🟨🟨⬜⬜🟩
🟩🟩🟩🟩🟩
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 549 5/6*
⬜🟨⬜⬜🟨
⬜🟨🟨🟩⬜
⬜🟨🟩🟩⬜
🟩⬜🟩🟩⬜
🟩🟩🟩🟩🟩
Happiness will never come to those who fail to appreciate what they already have. -Anon
|
|
|
|
|
Very apt...
Wordle 549 3/6*
⬜🟨⬜⬜⬜
⬜🟨🟩⬜🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 4/6
⬛🟨⬛⬛⬛
🟨⬛⬛⬛🟨
⬛🟩🟩🟩🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 549 5/6
⬛⬛⬛⬛⬛
⬛🟨🟩⬛⬛
⬛🟨🟩🟩⬛
⬛⬛🟩🟩🟨
🟩🟩🟩🟩🟩
Get me coffee and no one gets hurt!
|
|
|
|
|
Yep, here I go again. Working with windows for 25 years. Windows 7, 8, 10 - Xp - gasp - task bar with search at the bottom. Nah, let's change the default.
Okay, let's try dragging it around. Nope, doesn't work like Windows 7 or 10. Nah, why be consistent?
Google reveals I have to go to task bar settings - where I only have center and left selections. Microsoft claims this is a better user experience. huh
As a Christmas present to all of my listeners I am going to go purchase that task bar tool. Windows 12 will duplicate it, because what Microsoft did should have gotten a few people fired. For all of you who have criticized me for complaining or getting angry, you really cannot defend MS. If you do... well.
for the record, I'm building a new release. It would have been out earlier, but Microsoft rebooted all of my build VMs.
Ho ho ho.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: As a Christmas present to all of my listeners I am going to go purchase that task bar tool.
I assume that should be publish the task bar tool, not purchase?
Keep Calm and Carry On
|
|
|
|
|
no, there is a tool out there - Start11 - but it was supposed to do what I want but doesn't (make the W11 taskbar behave like W10).
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Devices and Printers now too.
It seems like settings might be more mobile friendly.
Aside from that I can't imagine what they are thinking day to day over there.
|
|
|
|
|
charlieg wrote: Xp - gasp - task bar with search at the bottom.
Not sure what that means but I don't think XP had a 'search' in the taskbar.
|
|
|
|