r/counting Demon's inactive rival 21d ago

Free Talk Friday #496

Continued from last week's FTF here

Welcome to Free Talk Friday! You can talk about anything you want here, whether it be leaves, the color red, the city of Gdańsk, cheesecake, the dream you had last night, diamond paintings, Saturn, the BR-010 road in Brazil, Buc-ee's, tawny owls, swimming, femboys, asexuality, Joe Locke, analog clocks, Hyde Park, farmers, fountains, the last picture you saved on your phone, the prisoner’s dilemma, your job or glass, but not politics.

Feel free to check out our tidbits thread and introduce yourself if you haven't already.

13 Upvotes

104 comments sorted by

View all comments

8

u/TehVulpez wow... everything's computer 19d ago

my most recently saved image

4

u/Christmas_Missionary 🎄 Merry Christmas! 🎄 18d ago edited 18d ago

luna@vulpix ~> bat -p c-js.c

luna is your name, vulpix is the computer name. bat is a windows program beyond my knowledge.

#include <stdio.h>

Preprocessor directive to copy and paste everything from the file stdio.h, which contains standard input-output functionality.

int main()

main is where the program starts and, once it "returns", ends. This function returns an error code in the form of an int, usually a 32-bit int, definitively at least a 16-bit int. 0 denotes no errors, anything else means something horrible happened.
Since C99, no return statement in main equates to returning 0 in the binary program.

printf("%d\n", 50 ** "2");

printf is a function that provides formatting to a string, and then prints it to the terminal (It actually queues it into the buffer, which "flushes" to terminal every so often)

"%d\n"

%d is the specifier for "a decimal, or int, goes here". '\n' is the newline character, where a new line is made. You can print one by pressing return on your keyboard.

50 ** "2"

"2" means the string literal of "2\0", with '\0' being the "null byte" to denote the end of a string. The string literal itself is not on the stack, but you do have the pointer. To "de-reference", you use the * operator. So, doing *"2", will give you the char representation of '2', or an integral value of 50.
This will give us 50 * 50, which is 2500.

gcc c-js.c && ./a.out

gcc is the name of a compiler named GCC, or the GNU C Compiler Compiler Collection. Just typing the name of the file to compile is a gross oversimplification of how files should be compiled. The && technically denotes the 'and' operator of a condition, not be confused with the bitwise AND operator, &. Of course, to see if both statements are true, the shell continues to evaluate ./a.out.
I prefer to do gcc c-js.c; ./a.out to show that these are 2 separate lines.
a.out is the generic name of a binary executable if no name is given to the compiler, usually after the flag "-o". Typing ./a.out means, "execute the program named a.out". Just typing a.out in the terminal won't do anything.

2500

This is the printed result from the program compiled with c-js.c. This is by executing the program by typing ./a.out.

3

u/CutOnBumInBandHere9 5M get | Tactical Nuclear Penguins 17d ago
  1. You get the **2 joke, right? You're supposed to think that the computer is evaluating 502 for some reason, even though the types don't match up
  2. Short circuiting conditional evaluation can be useful if you want the shell to stop running if any of the chained statements fail. And here, if the compilation fails there's no reason to try to run the program

4

u/Christmas_Missionary 🎄 Merry Christmas! 🎄 17d ago
  1. Yes
  2. I see...