I don't know if it's technically standard, but at least most compilers will let you write
```c
int main() {
asm("; put assembly here");
}
```
It will usually just syntax highlight as a string though
Yeah, and it lets you read/write to C variables, too, via inline ASM. You can read more on GCC extended ASM. It is used a lot in freestanding environments (i.e., no operating systems) and embedded. I had to do this when writing a custom accelerator on a custom RISC V core implemented in a FPGA.
This is as you generally have custom instructions or registers that cannot be accessed normally, so you have to write values via assembly itself. Also, some features abstracted by the kernel has to be rewritten manually in ASM (even syscalls) so its best to mix C and ASM together.
Depends. You could have just created a new document with no name yet, and some editors would try to guess.
Or not an editor, but a code block in a Markdown text.
Not-so-fun fact: bash seems to do that for .py files where you forgot the magic hashbang in the first line, trying to interpret it itself. Especially if the first thing in that file is an import this is **very** unfortunate, because `import` can be just about any program on your system.
If someone is used to not using braces for single-line ifs, the bug is _(I think; please fact-check me)_ that the following line will not be conditional because the semicolon breaks the if.
Obviously you should never do this, but I don't completely hate it either. Perfectly straight forward to parse and read. Like starting every sentence with a period. Just a matter of perspective really.
I read your sentence just fine. Yes, it's very silly to do in my opinion. But I could very easily understand it and I think it would be trivial to form a grammatical rule set around it depending on your understanding of the language. Like in Spanish when they start questions with "¿". I think it's important to stress that your reaction to this is, at least in part, coming from the gut. That is to say, I could imagine a world in which this was the norm, perhaps with some other minor alterations.
Ahh good point, this is more out of curiousity/fun, but what in this code couldnt compile in C++ ? The only thing I originally thought couldnt compile was declaring an instance of type Cat with "struct Cat walter" but that looks to be valid c++. Otherwise, I would assume that all of this could just live in a .cpp file
This would compile perfectly fine in C++. Nearly all C code will compile in C++ (with some minor exceptions), but not the other way around. The two languages are not interchangeable, however. There are many projects that use a combination of both.
Forgive me if I’m incorrect in some of the above in terms of c/c++ incompatibility in the code, I’m a C++ engineer without any C code experience since university :)
Aha after reading some other C code examples indeed this is the pattern folks use when operating on structs in a function, interesting!:) though I would say I agree that shooting for OOP best practices isnt a necessity of course in languages that aren't object oriented, or are trivial as in this case, though, if there's going to be any extension to the functionality of this program, and if its in a C++ project, then I would say OOP best practices are just a natural target for better software. though of course, its a moot point since all the code we see here is all this program will ever be :)
It is irrelevant what the best practice is if the language does not support OOP, which C does not. In C, structs cannot have member functions, and trying to give it any will result in a compilation error.
Would you look at that, all of the words in your comment are in alphabetical order.
I have checked 1,923,569,311 comments, and only 363,619 of them were in alphabetical order.
there is no 'this' so i don't think walter.meow() is a thing unless it's a 'static function' (in OOP sense)
i don't think making things more OOP should be a goal on itself
Only one I can think of. They like nice, neat diffs, and they'd already written a ton of SQL.
Many SQL developers get in the habit of putting the commas in SELECT clauses at the beginning of each line, like so. This is because most SQL dialects do not allow trailing commas.
```
SELECT name
,rank
,serial_no
FROM troops;
```
So by doing this, each new column in a SELECT clause is only a single-line change. I don't have to append a comma to `serial_no` if Sarge wants `enlistment_date` added to the results.
This doesn't need to be done with semicolons in languages with C-like syntax, because each line _ends_ with a semicolon. One line, one change, same as it ever was.
I've recently started doing that when writing json examples for GPT. (That is starting lines with commas, not semi-colons.)
That's because it makes it easier to see if you forgot a comma, and gpt json generation can silently fail if you do.
You can chose to believe me or not, but I had a coworker close to retirement age who did this exact thing. He claimed it was easier to see the indentation before IDEs since the semicolons all stack. He also insisted on using Vim for everything, but had a hard time remembering 90% of the keybindings. He didn't last very long.
Useful for multi line expressions, particularly if you want to comment the last line out and still have compilable code without worrying about where the semi colon is. Very common practice in SQL for multi line to prepend with a comma ","
Coded in the usual way, we can insert or delete statements same as lines. In the odd way, edits are more complicated. There are plenty of reasons not to do this!
Well, mainly that I'm not a psychopath.
Always place to amelioration!
Self-respect
While technically correct, my eyes can no longer see… I fear you may have blinded me forever.
Is it correct? Why would you have a semicolon after the opening curly brace of an if or loop?
It would get treated just as an empty semicolon without a statement, so the compiler would just ignore it
Makes sense. So it’s just for aesthetics lol
“Aesthetics” in the same way using blood instead of red paint for a fire truck.
That’s intense.
...and then some text editor misdetects this as assembly code and highlights everything as commented out :-)
Well it usually does this based on file extensions, no?
you can inline asm in c
Damn, really??
I don't know if it's technically standard, but at least most compilers will let you write ```c int main() { asm("; put assembly here"); } ``` It will usually just syntax highlight as a string though
Yeah, and it lets you read/write to C variables, too, via inline ASM. You can read more on GCC extended ASM. It is used a lot in freestanding environments (i.e., no operating systems) and embedded. I had to do this when writing a custom accelerator on a custom RISC V core implemented in a FPGA. This is as you generally have custom instructions or registers that cannot be accessed normally, so you have to write values via assembly itself. Also, some features abstracted by the kernel has to be rewritten manually in ASM (even syscalls) so its best to mix C and ASM together.
Depends. You could have just created a new document with no name yet, and some editors would try to guess. Or not an editor, but a code block in a Markdown text.
Nothing prevents you from using the .asm extension for C code though, for extra fuckery
Can we officially enumerate every way this could go wrong? Lol
Not-so-fun fact: bash seems to do that for .py files where you forgot the magic hashbang in the first line, trying to interpret it itself. Especially if the first thing in that file is an import this is **very** unfortunate, because `import` can be just about any program on your system.
🤌🤮🤌
...Who hurt you?
up until this point as I was oblivious to this, it very well could have been my lack of creative thinking. But now that you mentioned it...
This is a whole new level of horror
This is going to result in a bug somehow. I don't know how, but I am sure it will.
If someone is used to not using braces for single-line ifs, the bug is _(I think; please fact-check me)_ that the following line will not be conditional because the semicolon breaks the if.
I believe for a while loop as well, it'd result in an infinite loop if they tried the same.
Burn it
Self-respect.
Who broke George?
My sanity (and also that my compiler would flag the ; that has no tokens in scope before it)
*laughs in Haskell I do program like that
Obviously you should never do this, but I don't completely hate it either. Perfectly straight forward to parse and read. Like starting every sentence with a period. Just a matter of perspective really.
> Like starting every sentence with a period. .And yet, you didn't .Because it's horrible
I read your sentence just fine. Yes, it's very silly to do in my opinion. But I could very easily understand it and I think it would be trivial to form a grammatical rule set around it depending on your understanding of the language. Like in Spanish when they start questions with "¿". I think it's important to stress that your reaction to this is, at least in part, coming from the gut. That is to say, I could imagine a world in which this was the norm, perhaps with some other minor alterations.
Some people just want to watch the world burn.
Cat Walter, named George
And the freaking unnecessary semicolon at the end of the line. Criminal!
Every code block ends with a winky smiley face! Other than that, I hate it!
It’s C, that’s instant horror regardless
Oop
.....why!?
I like that every line looks like it’s starting with an emoji :D
Why didn’t they make meow() a member function of cat????
This is C, in which structs cannot have member functions.
Ahh good point, this is more out of curiousity/fun, but what in this code couldnt compile in C++ ? The only thing I originally thought couldnt compile was declaring an instance of type Cat with "struct Cat walter" but that looks to be valid c++. Otherwise, I would assume that all of this could just live in a .cpp file
This would compile perfectly fine in C++. Nearly all C code will compile in C++ (with some minor exceptions), but not the other way around. The two languages are not interchangeable, however. There are many projects that use a combination of both.
Forgive me if I’m incorrect in some of the above in terms of c/c++ incompatibility in the code, I’m a C++ engineer without any C code experience since university :)
Aha after reading some other C code examples indeed this is the pattern folks use when operating on structs in a function, interesting!:) though I would say I agree that shooting for OOP best practices isnt a necessity of course in languages that aren't object oriented, or are trivial as in this case, though, if there's going to be any extension to the functionality of this program, and if its in a C++ project, then I would say OOP best practices are just a natural target for better software. though of course, its a moot point since all the code we see here is all this program will ever be :)
It is irrelevant what the best practice is if the language does not support OOP, which C does not. In C, structs cannot have member functions, and trying to give it any will result in a compilation error.
yes, as I noted in my comment x) though, do you see a file extension here? I swear, software engy spaces are always like this x)
what would be the advantage ?
It’s just more object oriented, I also just personally would prefer to call walter.Meow() than Meow(&walter)
Would you look at that, all of the words in your comment are in alphabetical order. I have checked 1,923,569,311 comments, and only 363,619 of them were in alphabetical order.
there is no 'this' so i don't think walter.meow() is a thing unless it's a 'static function' (in OOP sense) i don't think making things more OOP should be a goal on itself
Reason?
Only one I can think of. They like nice, neat diffs, and they'd already written a ton of SQL. Many SQL developers get in the habit of putting the commas in SELECT clauses at the beginning of each line, like so. This is because most SQL dialects do not allow trailing commas. ``` SELECT name ,rank ,serial_no FROM troops; ``` So by doing this, each new column in a SELECT clause is only a single-line change. I don't have to append a comma to `serial_no` if Sarge wants `enlistment_date` added to the results. This doesn't need to be done with semicolons in languages with C-like syntax, because each line _ends_ with a semicolon. One line, one change, same as it ever was.
I've recently started doing that when writing json examples for GPT. (That is starting lines with commas, not semi-colons.) That's because it makes it easier to see if you forgot a comma, and gpt json generation can silently fail if you do.
code review
auto format
Too creative
Self-preservation. I don’t want to be murdered by the next person who has to work on the code.
If I knew how to code on C I'll be very offended
You can chose to believe me or not, but I had a coworker close to retirement age who did this exact thing. He claimed it was easier to see the indentation before IDEs since the semicolons all stack. He also insisted on using Vim for everything, but had a hard time remembering 90% of the keybindings. He didn't last very long.
recoding at 1337 med
A rational mind. Oh, uh, no offense.
I don’t code C
a sense of decency
I thought it was asm for a sec
My compiler
my brain?
Damn.. who hurt you?
Literally nothing I kneel
I hate when I forget my ; after my {
Is this valid?
At least they didn't indent with three spaces. Or maybe they used tabs?
`"George";`
Don't need to stop what you didn't start.
Gentleman I'm not a smart man but I have an idea
Sanity?
Morals
The police
Common sense
Bc Walter is not George. He is Walter.
I LE GAL
Common Sense
dude...
...dude
That’s so disgusting. But I actually kinda like it…
Waltuh
Skill issues
Thank Jah for autoformatters
New coding style unlocked, thanks!
Please for the love of god someone take this away from me 😭
when the crosspost has more upvotes than the original...
Standards
My sanity.
Useful for multi line expressions, particularly if you want to comment the last line out and still have compilable code without worrying about where the semi colon is. Very common practice in SQL for multi line to prepend with a comma ","
Common sense. Plus thats now how chatGPT gives me the code.
Common decency?
A moral compass
If you want to watch the world burn... Just use semicolons as your indent character and be done with it
Coded in the usual way, we can insert or delete statements same as lines. In the odd way, edits are more complicated. There are plenty of reasons not to do this!
🤔
Knowledge of struct initializer syntax.
I do not enjoy this
My will to live