Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did this code still work?

Some old code that I just came across:

MLIST * new_mlist_link() {     MLIST *new_link = (MLIST * ) malloc(sizeof(MLIST));     new_link->next  = NULL;     new_link->mapi  = NULL;     new_link->result = 0; } 

This was being called to build a linked list, however I noticed there is no statement:

return new_link; 

Even without the return statement there, the list still got built properly. Why did this happen?

Edit: Platform: Mandriva 2009 64bit Linux 2.6.24.7-server GCC 4.2.3-6mnb1

Edit: Funny... this code also ran successfuly on about 5 different Linux installations, all different versions/flavors, as well as a Mac.

like image 968
user318747 Avatar asked May 05 '10 20:05

user318747


People also ask

Why can't I redeem codes in Genshin?

1. Before redeeming a code, log in to your account and make sure you have created a character in the game and have linked your HoYoverse Account in the User Center. Otherwise, you will be unable to redeem the code.

What does it mean when it says this code is not yet active contact the merchant to activate this code?

If you're seeing the message “This code is not yet active” when you try to redeem your code, it means that you have a valid digital code, but it's not yet been activated by the retailer. You'll need to contact the retailer and ask them to activate the code.

How do you explain a code?

Learn to code by breaking it down into lines and chunks. Explain Code gives you line by line explanation of code. It helps you in learning programming concepts and improves your coding skills. Reduce the time to understand code by summarizing it into one containing code and description.

Why can't I redeem my Xbox game pass code?

Make sure that you didn't already redeem the code, possibly under a different gamertag or Microsoft account. If you're having trouble redeeming a digital code, it may be due to a service outage on our side. Check the Xbox status. If you see any alerts, wait until the service is up and running and then try again.


1 Answers

On 32-bit Windows, most of the time, the return value from a function is left in the EAX register. Similar setups are used in other OSes, though of course it's compiler-specific. This particular function presumably stored the new_link variable in that same location, so when you returned without a return, the variable in that location was treated as the return value by the caller.

This is non-portable and very dangerous to actually do, but is also one of the little things that makes programming in C so much fun.

like image 149
Aric TenEyck Avatar answered Oct 02 '22 17:10

Aric TenEyck