This is the archive of the old Colorless! Go to the new Colorless →

C. (Thread) - Page 4

Well, most things I write these days are in C, so...

... what I'm currently writing on (Other than university-related things) is rendering code for what might become a small game. It seamlessly combines distance field rendering (via sphere tracing) with standard rasterization.

Looks like this right now:

http://halcy.de/misc/opengl/sinewraplambert.png

http://halcy.de/misc/opengl/wehavethetechnology4.png

Next up is making the camera move along the distance field.

OpenGL... daaang man. You are most impressive.

So I decided to have fun with the C pre-processor last night and ended up having code that looked like this at the end:

  
MAIN  
  
    RED STDOUT "Hello World!\n" CLOSE  
  
    COLORLESS STDOUT "^ COLORS OMG\n" CLOSE  
  
    RETURN 0 END  
  
ENDLOOP  

I'm contemplating submitting every program I make for my programming class next semester like this... Wonder if the grader's head will explode into thousands of pieces if I do that.

@Shigeru

Lol nice, if they don't get it, but yet it works, they can't possibly fail it xD

When I get into uni, we're going to make our own languages, write our own compilers etc. It's going to be awesome :P

@RangleGoose yeah? You'd have to tell us about it all.

Anyway, the other day I tried using a different compiler (MinGW) so I can run programs natively on Windows. I ran into a problem though. I'm too used to gcc and didn't realise that Windows does not recognise the getline() function, which I tend to use a lot.

Are there any good alternatives to getline() for MinGW? Please don't say scanf() because I will freak out at you if you do. XD

And I guess for note, a lot of my code nowadays looks like this:

string = (char*)malloc(BUFFER_SIZE+1);  
bytes_read = getline(&string,&BUFFER_SIZE,stdin);

The second line there is what's causing problems for MinGW (not Cygwin though it works wonderfully otherwise) so... yes if you have a solution to that I'd appreciate it.

Can someone here teach C+ please? Or at least show me a good place to start learning it from?

@Izaya-TheKiller Uh, I'm assuming you mean C++? Or plain C?

Well, if you have any specific questions, I can probably answer them (unless it's about the more obscure features of C++, I am no good with that). For general learning... well, do you have any previous experience with Programming? C and C++ are neat languages, but I am not sure they are very good languages to get into programming with. Python is supposed to be good for that, though I don't know it myself. Any dynamic language that is halfway powerful (Perl, PHP, Ruby, ...) will probably be okay.

If you are already familiar with how programming, generally, works (If you have a basic understanding of how to control the flow of a program, really), a good document for picking up C is, supposedly, Learnining GNU C. It somewhat assumes that you are running a system that has gcc and gnu libc installed (linux, *BSD, windows with mingw, ...). C++ is very similar to "C with some things extra", learning C first probably doesn't hurt. I don't know any good C++ tutorials or textbooks.

If you're looking to learn a new programming language, may I suggest shamelessly plug #/g/sicp on Rizon IRC network? It is probably the friendliest programming channel I've ever been to, and there are always seasoned programmers on who are more than willing to give you resources and point you in the right direction.

I'm currently taking computing class. JavaScript is really messing with my head. I don't understand how can people do this.

@mizlily

For utter beginners, some tips:

  • It is important to realize that the computer will always do EXACTLY what you tell it to do, and nothing else. If you tell it to do the same thing again, it will do the same thing. The computer does not decide things. It just idiotically follows whatever orders you give it.

  • In imperative programming, which is most of what you will be learning at first, the program is sort of like a recipe: A list of instructions that must be executed in the order they are given. The computer will always do exactly that and nothing else.

  • The probably easiest way to learn programming is to program. Write code. If it doesn't work, figure out where you gave the machine the wrong instructions, and give it the right ones instead. Do that until you have a model of how the machine works in your head. Read code. Try to see what it does before running it. Eventually, it will become easier.

  • Once you understand the basics of manging control flow - telling the machine to do something in some condition and something else in another, or telling it to do something repeadetly - everything else becomes much easier.

  • Seriously, the computer never does anything but what you tell it to do, and it does not throw dice nor reason nor try to help you when you tell it stupid things, if you told it to jump out of the window it would, if it could. Internalize that. It might seem strange to insist on this so much, but this is something that many people seem to have trouble understanding at first.

You are on the old site. New site is here:

The site has been updated on the 24th December 2011. Please go there when you are finished with the archives.

  • 481,435 posts
  • 2,075 threads
  • 23,121 users