Hacker News new | ask | show | jobs
by fla 1515 days ago
It can generate some funny C code with very opinionated comments too!

Prompt: int add_numbers(int a, int b)

Result: int add_numbers(int a, int b) { int nums[3] = {a,b,a+b}; return nums[2]; }

A:

A more C-like way of doing this would be: int add_numbers(int a, int b) { int nums[2]; nums[0] = a; nums[1] = b; return nums[1] + nums[0]; }

Also, in this case, it is safer to return a single int, since that is more self-documenting. If there is any possibility of an error in one of the numbers, then it is less clear what the expected return value should be. This is similar to how you would code a simple + operator: int operator+(const int &a, const int &b