#Should I try to completely understand everything about C before moving on to newer languages ike C++

128 messages · Page 1 of 1 (latest)

hidden tusk
#

Dumb question I know but I just wanted to ask how much of C should I try to understand before moving on to other languages since my professor Is done with C and will most likely move on to C++ so I wanted to be done with C first since there is a lot of stuff I still don't know about it

steep cedarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

chilly orchid
#

there is a lot of stuff I still don't know about it

it's fine

hidden tusk
#

I don't know every time I ask a question here I find out about 10 more things

chilly orchid
#

when I passed my linear algebra lesson for the first time, I didn't rank quite well (a poor 14/20). the affine geometry lesson next semester, was entirely based on that one class. I studied for that exam, and presented that one and the linear algebra one again, to increase my score (without studying, because the teacher was nice: he kept the best score for students that represented in June, as a favour. since I had many other exams, I just didn't study and tried anyway). I got 18 and 19, respectively.

chilly orchid
# hidden tusk It is?

you might review C concepts while learning C++, get haha-moments, and understand better anyway

#

there are different theories, but often people tend ot agree that good programmers are programmers that know different languages on surface (because it shows they came accoss different paradigms and ideas), and are able to dig deep into one when required (because they understood the concepts). knowing all C by heart, doesn't sound like a requirement right now

hidden tusk
hidden tusk
chilly orchid
#

that's already nice

hidden tusk
#

Thanks a lot for the help man

bright mulch
#

I hope sincerely that you are eased into C++ and not dropped straight into the deep end. Modern C++ scares even me with all the templating and whatnot.

chilly orchid
bright mulch
#

I know that there will be things you will immediately love and you may even start criticizing C somewhat.
A very simple example of that being function overloading.

hidden tusk
hidden tusk
hidden tusk
neat hemlock
#

I would say it is a good idea to learn C++ and since you already know some C it won't be as difficult as a newcomer to the languages.

bright mulch
#
void foo(int arg);
void foo(float arg);

int main()
{
  int i = 5;
  float f = 5.0;
  foo(i);      // calls the int version
  foo(f);      // calls the float version
}
neat hemlock
#

also I don't think you can overload the main function

bright mulch
#

No, even in C++ you cannot overload main().

hidden tusk
#

Oh

#

So it's just for multiple user defined ones with same name?

neat hemlock
#

templates are one of the main things that make me want to stay writing C++ over C

bright mulch
#

Going from naught to C++23 will scare most.
I hope that you start off aiming for C++03 or perhaps C++11.

neat hemlock
#

The STL is also amazing compared to not having it at all

neat hemlock
#

But yeah totally agree C++23 is massive

hidden tusk
bright mulch
bright mulch
hidden tusk
#

Damn 23? It's still getting updates?

neat hemlock
#

Not a tutorial site though

neat hemlock
#

There's C23 (or C2X I don't remember)

bright mulch
#

cppref has already started mentioning C++26 I noticed the other day.

hidden tusk
lost glen
bright mulch
#

Like a roadmap?

lost glen
neat hemlock
#

@bright mulch Have you used coroutines in any code yet?

hidden tusk
neat hemlock
#

I personally haven't - but I really never see a good time to utilize it (and also am still new/learning it)

neat hemlock
#

the site I mentioned also has information on C too

bright mulch
hidden tusk
neat hemlock
#

Hey that's not too bad! At least you're not on C++11 - not saying I am but that would not be great

neat hemlock
hidden tusk
neat hemlock
#

Wait where

#

Are you talking about C++26?

bright mulch
#

If true, it seems that 2026 is a unique year in that it brings out new standards for both C and C++.

hidden tusk
#

It says on that website

neat hemlock
#

I think they are supporting reflection in C++26

hidden tusk
#

Mb I accidentally said C26 instead

neat hemlock
#

if so that should be interesting

hidden tusk
#

Oh

#

Damn

bright mulch
# lost glen yeah, as it seems to be a roadmap

To be honest, even though C++26 has been announced, its contents will be quite fluid.
Some stuff may not be ratified.
Other stuff may be brought into the mix.
A roadmap for C++26 would be largely a work of fiction.

hidden tusk
#

Man I can't wait to just jump into C++ now after my finals

neat hemlock
neat hemlock
hidden tusk
polar lintel
#

im thinking

neat hemlock
#

Also like the idea of std::hive

polar lintel
#

i went into C++ before i knew the basics of C and genuinely

neat hemlock
#

That one is intriguing

polar lintel
#

i still think C is harder 💀

#

i literally went down the ladder instead of up (C#->C++->C) and ngl C just makes it way harder to do anythin

neat hemlock
#

yeah there are less abstractions which make it seem harder

polar lintel
neat hemlock
#

C strings are pretty sad compared to C++ strings

polar lintel
#

i still dont know how to read anything of any size from a stream

#

is that even possible

neat hemlock
#

string?

#

strlen

polar lintel
#

with a C string

lost glen
polar lintel
#
fgets(buf, 1024, stdin);
``` in example i dont know how to make that 1024 entirely variable
neat hemlock
lost glen
#

I think you mean string utils, If not, I suppose cppstrings keep the null terminator rule

bright mulch
#

But, with C you are in complete control, so this is why it is so popular with embedded.
For instance, using the STL you think arrays (is: vector) just became 100x easier.
But if you let it, STL will use heap for anything dynamic.

That's the stuff of nightmares in embedded.
So then you need to learn allocators to ensure that you control dynamic allocations.
And suddenly something as simple as arrays isn't so simple after all.

neat hemlock
polar lintel
bright mulch
#

allocators.

lost glen
#

you can allocate scalable memory within the stack?

bright mulch
polar lintel
#

also isnt fam and vla technically just heap under the hood too or am i stupid

neat hemlock
#

no idea, I stay away from VLAs

polar lintel
lost glen
bright mulch
#

Example:
In threadx, you can create byte pools.
You can do new and placement new, and redirect from heap to these byte pools.

These byte pools could be a stack buffer.
Or an area in the .bss.

steep cedarBOT
#
What Is a VLA, and Why Is It "Bad"?

A Variable Length Array (VLA) is an array where the size is not constant and depends on a variable.

Example
int size = rand();
int vla[size]; // VLA of type int[size]
int not_vla[10]; // regular array of type int[10]
constexpr int size = 10;
int arr[size]; // also not a VLA, of type int[10]
Why Are VLAs "Bad"?

VLAs have poor compiler support and can lead to unsafe code. The core issue with VLAs is that the compiler doesn't know the size of the stack frame. Without warning flags like -Wvla, it can be easy to create a VLA by accident, even in C++ with some compilers.

Compiler Support

:white_check_mark: available since C99
:no_entry: not available in C++ at all
:no_entry: was never supported by MSVC
:warning: optional feature since C11
:warning: supported as non-standard extension by GCC, clang

chilly orchid
#

VLA to allocate memory is a really bad idea

polar lintel
#

;compile -Wvla -std=c23

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

constexpr int sqr(int x) {
  return x * x;
}

int main(void) {
  srand(time(NULL));

  int i = rand() % 30;
  int arr[sqr(i)];

  printf("%zu", sizeof arr / sizeof i);
}```
fleet skiffBOT
#
Compiler Output
<source>:5:1: error: 'constexpr' requires an initialized data declaration
    5 | constexpr int sqr(int x) {
      | ^~~~~~~~~
<source>: In function 'main':
<source>:13:11: error: implicit declaration of function 'sqr' [-Wimplicit-function-declaration]
   13 |   int arr[sqr(i)];
      |           ^~~
<source>:13:3: warning: ISO C90 forbids variable length array 'arr' [-Wvla]
   13 |   int arr[sqr(i)];
      |   ^~~
Build failed
chilly orchid
#

VLA to implify size computation, is a good idea

lost glen
# steep cedar

ah, so It is generally a bad idea to define an array's width with a non-constant integer expression

polar lintel
#

so tha'ts not vla?

chilly orchid
#
int x, y; // assume given at runtime

double m[x][y]; // bad vla usage
double (*m)[x][y] = malloc(sizeof(*m)); // friendly vla usage
lost glen
neat hemlock
polar lintel
#

why would you need to cast malloc

bright mulch
#

You wouldn't even be doing malloc() in C++.

neat hemlock
#

Since it of type void*

neat hemlock
#

ok

chilly orchid
#

ah wait, we are in C++ ?

bright mulch
#

No, but the question is about C++ after C.

chilly orchid
#

aaaaah

bright mulch
#

Still a good point (vla), though.

#

Plus OP would have learned about new vs malloc pretty damn early on anyway.

neat hemlock
polar lintel
neat hemlock
#

but yeah, who needs malloc

steep cedarBOT
#

@hidden tusk Has your question been resolved? If so, type !solved :)

hidden tusk
#

!solved

steep cedarBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity