Live data from Hacker News

Main is usually a function – when is it not?

jroweboy.github.io

41–50 of 62 posts

Re: Main is usually a function – when is it not?

#41
post #40
post #33

The reason that I use C many of times is not because of its speed but because it (almost) completely reveals it inner working even when there is clear reason not to do so. (1) Though it is bad for most of time but still I feel more contended sometimes with it, especially for complex code. (2) Even if this transparency is at superficial level with optimising compilers, but there are very few high level optimisation ap…

For this type of stuff, I rather use a Macro Assembler.

For this type of stuff, I use... NOTHING. NOTHING AT ALL. I DON'T DO IT. BECAUSE IT IS INSANE.

Gloriously, wonderfully insane, though. My compliments to the chef.

Re: Main is usually a function – when is it not?

#42

I like this little project of how one person delved into the fun. But as far as the TA goes, most people who have an interest in C and programming will look at the source and say to themselves "Oh, byte values of machine code being executed, yes very clever but do the assignment again properly."

If that is the case then the education system is thoroughly broken. It is obvious that a person who took the time to do that learned far more than they would than had they copied one of millions of Hello World examples from the internet.

That being said, I wouldn't rule out a bored TA opening the file not seeing a printf and assigning a grade based on submitting something.

Re: Main is usually a function – when is it not?

#43
post #3

I wonder if one could write a header file containing definitions that would make the following possible. char main[] = { movl(1, eax), movl(1, ebx), movl(message, esi), movl(13, edx), syscall(), movl(60, eax), xorl(ebx, ebx), syscall(), }; Obviously there are some technical difficulties like handling literal values and code sections, but it could be a fun hack, and I've love to see what someone could come up with.

With enough macros you can do anything. I'm not aware of anyone doing this in C, but this is a cool example of doing approximately the same thing in a more easily extensible language: http://wall.org/~lewis/2013/10/15/asm-monad.html

Re: Main is usually a function – when is it not?

#44
Wait, what kind of company forces one of their programmers to take an intro level comp sci course? If you're going to let people hire someone to do a job, maybe you should either trust their judgement or have someone senior work with them to fix obvious defects?

I don't know, something about that just didn't sit right with me.

Re: Main is usually a function – when is it not?

#45

I like this little project of how one person delved into the fun. But as far as the TA goes, most people who have an interest in C and programming will look at the source and say to themselves "Oh, byte values of machine code being executed, yes very clever but do the assignment again properly."

If that is the case then the education system is thoroughly broken. It is obvious that a person who took the time to do that learned far more than they would than had they copied one of millions of Hello World examples from the internet. That being said, I wouldn't rule out a bored TA opening the file not seeing a printf and assigning a grade based on submitting something.

Not at all; TAs are paid poorly, have other more interesting work (i.e., their research) to do, and spending the time to deal with 'clever' is not a good usage of time. Sure the student learnt more, but that doesn't mean this is what they should have handed in. Have fun on your own time, but don't waste the TAs time.

Re: Main is usually a function – when is it not?

#46

Wait, what kind of company forces one of their programmers to take an intro level comp sci course? If you're going to let people hire someone to do a job, maybe you should either trust their judgement or have someone senior work with them to fix obvious defects? I don't know, something about that just didn't sit right with me.

That's almost certainly not what happened here. He was probably doing a Masters or something in a related field which had this requirement.

Re: Main is usually a function – when is it not?

#47

Wait, what kind of company forces one of their programmers to take an intro level comp sci course? If you're going to let people hire someone to do a job, maybe you should either trust their judgement or have someone senior work with them to fix obvious defects? I don't know, something about that just didn't sit right with me.

[deleted]

Re: Main is usually a function – when is it not?

#48
post #18
post #17

Wouldn't this be considered academic fraud? His coworker turning in code that he didn't write?

Probably not, since this isn't a case where my co worker can just copy paste my code and hope it works for two reasons. The first is I am not entirely sure their testing environment is using 64 bit linux, it could be 32 bit linux since I'm not in the class, I just assumed its 64bit so I could test it on my machine. The next reason is they don't actually have a Hello World assignment at all! The reason I wrote this ar…

> The first is I am not entirely sure their testing environment is using 64 bit linux, it could be 32 bit linux

Maybe it's ARM, or MIPS, or… Followup problem: write a sequence of bytes that performs a jump on one architecture, and something harmless or reversible on the other(s).

Re: Main is usually a function – when is it not?

#49
I remember something similar that enabled you to embed machine code in VB6 programs, which involved a magic constant that was sort of an entry point into a string containing opcodes. I don't remember the specifics, it's been a while, but nowadays it's very likely a horrible no-go anyway because you're executing data.

Still, was a nifty trick that allowed you to get more performance out of a language that wasn't very fast to begin with.

Re: Main is usually a function – when is it not?

#50
post #25

See also http://www.ioccc.org/1984/mullender.c (30 years ago). Hint at http://www.ioccc.org/1984/mullender.hint

Not having access to a PDP-11 (maybe this works on an emulator?) is it cheating to ask what the output of this program is?

According to http://www.ioccc.org/faq.html, it is equivalent to

  main(){
    int i=512;
    do
      write(1,"  :-)\b\b\b\b",9),usleep(i);
    while(--i);
  }
So, it moves a smiley on the screen, at increasing speed.
Post reply on HN