How can I gain a deeper understanding of C/C++?

Started by
53 comments, last by Irlan Robson 10 years, 4 months ago

Some of the advices might be true here. But if you really want to understand how programming and computers really work together, you should learn Assembly language, at first you might be scared of it, because a lot people think it's the holy grail of programming languages, and they think that only best of the best can learn it.

Ah, yep. Saw the title, read the post, scrolled down and someone beat me to it.

If you want a deep understanding of what's going on under the hood, then take the hood off. Learn assembly and start using the disassembly view in your debugger to see what your compiler does in order to implement things. It's fun, it's hands-on, and it will change the way you look at the code you write.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Advertisement

A deeper understanding requires a lot of questioning.

Use the 5 W's (What, Who, Where, When , Why) and 1 H (How?)

A big part of programming is problem-solving. Find the cause and diagnose the problem. Figure how to solve it.

.

.

I didn't mod you down, so I can only guess what part of your post bothered others. What do you think "syntactical" means? The syntax of C is very easy to learn, and C++'s syntax is not all that hard to learn either. The tricky parts of the language are primarily about things like what is guaranteed behavior by the standard, how do compilers actually implement it, and how have these things evolved.

Using libraries written by others is a great way to learn how to write clean interfaces, which is a very good thing indeed, but it has little to do with this thread.

If you like the type of things in the video, what happens when you compile this C program?

#include <stdio.h>

int main(void) {
  char a[2] = "42";
  printf("%c%c\n", a[0], a[1]);
}

What does this C++ program do?

#include <iostream>

int main() {
  volatile char const *s = "Hello,world!";
  std::cout << s << '\n';
}

The best way to learn new syntactical concepts is to use libraries written by others.

syntax is good to know but in terms of deeper understanding it realy means understanding the underlying language of C++. What is really going on is the question.

You have to find the C++ within yourself. Wax on, wax off.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

What does this C++ program do?

#include <iostream>

int main() {
  volatile char const *s = "Hello,world!";
  std::cout << s << '\n';
}

Might be better if fewer people knew this one. Volatile variables are rarely useful, except in specific fields, and that's a bad example of their use. It's also something that can easily be learned when it is encountered as opposed to being part of a rounded C/C++ knowledge base. If it weren't for its contagious semantics, volatile would be better off in a rarely used c header, like va_args and friends.

What does this C++ program do?

#include <iostream>

int main() {
  volatile char const *s = "Hello,world!";
  std::cout << s << '\n';
}
Might be better if fewer people knew this one. Volatile variables are rarely useful, except in specific fields, and that's a bad example of their use. It's also something that can easily be learned when it is encountered as opposed to being part of a rounded C/C++ knowledge base. If it weren't for its contagious semantics, volatile would be better off in a rarely used c header, like va_args and friends.

I agree. I like it as an example of dark corner of the language. g++ happily prints a 1 and doesn't even warn you about the conversion to bool that nobody expects.

The other snippet is a subtle difference between C and C++ that few are aware of.

They are both just curiosities.

This topic is closed to new replies.

Advertisement