just gonna make this a thread for any time I complain about smth my prof is doing/saying
mute this thread if you don't wanna see it
not from my prof but from cppreference.org
double* p = new double[]{1, 2, 3}; // creates an array of type double[3]
auto p = new auto('c'); // creates a single object of type char. p is a char*
auto q = new std::integral auto(1); // OK: q is an int*
auto q = new std::floating_point auto(true) // ERROR: type constraint not satisfied
what the fu-
why does it allow this.
also, my assignment has incredible requirements like:
All data members of user-defined class type must be of pointer type.
he explained this as "any data member and any variable and any assignment has to be pointers"
like. What.
or
All classes must implement a correct copy constructor, assignment operator, and stream insertion operator
like. what. why does it need an assignment operator (not a move constructor???) and a stream insertion operator.
using std::cout is cringe, use fmt::print/fmt::println (or std::print/std::println (or a logger which uses either of these)) and then implement a custom formatter.
also, not Everything needs a way to be formatted to stdout....
copy constructor is reasonable tho
but without a move constructor, the compiler won't be able to optimize things as well, but whatever
https://gustedt.wordpress.com/2025/01/06/simple-defer-ready-to-use/
hmmm
https://gustedt.wordpress.com/2026/02/15/defer-available-in-gcc-and-clang/
hmmmmmmm
I mean like. not the most convenient, buuuuttttt
why does he even need to explain
const int * const x = &foo;
this is quite easy to understand. constant pointer to a constant value. that is literally just how you read it?? why does this need an explanation??
void increase (void* data, int psize){
if ( psize == sizeof(char) ){
char* pchar; pchar=(char*)data; ++(*pchar); }
else if (psize == sizeof(int) ){
int* pint; pint=(int*)data; ++(*pint); }
}
unless I'm mistaken, according to the spec sizeof(char) can equal sizeof(int) (though, in practice, there are not really any systems where this is true, afaik)
also, I have not adjusted the formatting from the lecture notes presentation pdf. that's just exactly what he wrote
it seems that Texas Instruments C54x DSPs have 16 bit chars, I wonder if they use 16 bit ints? a quick search only gave me datasheets and I'm too lazy to look into it further
yeah it seems there are some DSPs where this is the case
Apparently, this one has 32-bit char, and, as a consequence,
sizeof(int)==sizeof(char)==1
>section in the notes titled "smart pointers"
>arrives at it
>"so we're not going to talk about smart pointers. we're going to skip this section"
NOOOOO
Pass by value cannot accept a parameter that is an expression.
...what?
By Reference:
- Drawback: cannot pass NULL , as a reference cannot be NULL
what? how is this a drawback? this is a good thing?
and if you need an optional value, std::optional exists
for the pass by value, is he thinking of pass by reference..?
because iirc if you initialize struct or whatever passed to smth that takes a reference, iirc the reference will go out of scope and not be valid (I could be misremembering this)
C++ provides following two types of string representations:
- C-style character strings
- string class type introduced with Standard C++
wrong! a char array is not a string. it is a char array.
Many libraries would define their own string type
back in like the fucking 90s?
ignoring glib (& any libraries that need a string with known length at compile time for funny template stuff), basically everyone just uses std::string (at least afaik, I could be mistaken, but I don't see it that often)
well, maybe some really large projects have their own string type. like I could see chromium doing that or smth
using namespace std;
STOPPPPP
I have another prof who actually knows what he's doing tho for a course where we look at multiple different languages (starting with C, then python, then clojure, then erlang)
NOOOOOO he mentioned make, said "the syntax is really obscure so usually we use a generator", then mentioned cmake and didn't mention something better like meson </3
(though he did say we're not going to be using either, and instead just invoking the command directly)
"when printing to a stream you can use the c-style \n or you can use std::endl"
do not use \n, it doesn't flush the stream...
he asks what the difference is between \n and std::endl
I respond that it flushes the stream
he says "no"
?????
that is LITERALLY what the difference is?
I have cppreference open right now. it literally says
Inserts a newline character into the output sequence
osand flushes it as if by callingos.put(os.widen('\n'))followed byos.flush().
what.
he just said that calling .open() on ofstream will cause the file to be locked
I don't think that's the case..?
but I could be wrong about that one
I think with pointers you usually define them with, uh, a star sign
(mind you, this was a TA and they probably mispoke, I just found it funny that they said "usually" here lol)
oh boy, time to learn what a struct and a class is!
(talking about header files in C++)
As opposed to Java classes, C++ allows to have class declarations that do not include the definition of the functions it encapsulates.
This enables the possibility to separate the class declaration from its implementation code, which provides the implementation of the member functions of a class.
I mean.. I guess it provides that possibility?
you can do this in java already with an interface though...
but like.. the main reason header files exist is because they come from a time when computers weren't powerful enough to be able to hold everything in memory and do multiple passes during the compilation process. they weren't really added for the purpose
I love learning about what arraylists are
??? my teacher just claimed that in java, ArrayList has a method .get(integer i)
no? integer is not a class that exist? the signature is #get(int)
why the fuck are we calling everything an "ADT"
in C++ they don't have an array list, they have something called vector
?????
in C++, std::vector is an array list??
how are we managing to explain linked lists in a way that is confusing
That is, in a list, each position b will always be after a position, a, and before a position c, except when b is the first or last position in the list
that is... a property of any finite sequence of integers?
favourites list ADT
what?
are we just making shit up now
he is explaining how this might be used with an example of a GUI which has a dropdown menu with 20-30 entries
his suggestion is that the application should track how often each menu item is pressed, and then only show the top 5 most pressed items
???
@solonovamax deadass HORRIBLE ux design đ
things should be kept at fixed positions!
@solonovamax IVAN uses its own string type for some reason (in C++). Also, a null-terminated char array is a string, otherwise C doesnât have strings.
@noisytoot imo C doesn't have strings, it has char arrays
char array != string
"in C, a char is 1 byte"
wweelllllll
my prof is telling me how doing array out of bounds checks is really expensive
and like.. yeah, it used to be, back when C was initially developed (also, C does not store length with the array), but like these days if the array is in L1 and the branch predictor is able to correctly predict the right branch (which it likely will), then it doesn't actually cost that much to do the check
also, like, if you're using C++ avoid C arrays and use std::array or whatever else...
"in Java, if you pass an array it will pass a copy of the array"
what?
no?
that's just wrong??
@solonovamax okay this one is at least a VERY common misconception
@privateger how? java just always does pass by reference. it NEVER copies.
the only scenario in which it sort of acts like it copies is when you pass a primitive. but if you understand java, this makes complete sense as to why.
@solonovamax This is completely backwards. Java never does pass by reference, ever. It canât. Itâs a pass by value language only, primitives follow the same rule.
Arrays (and other such objects) behave similarly to pass by reference because the copied value is the opaque reference value, but they are not. It is not possible to change what other references point to, only the referenced object can be modified.
Try writing a swap method: it wonât swap the callerâs variables.
@privateger what?
his is completely backwards. Java never does pass by reference, ever. It can't. It's a pass by value language only, primitives follow the same rule.
$ jshell
jshell> class Test {
...> public int x;
...> Test(int x) { this.x = x;}
...> @Override public String toString() { return "Test(x=%d)".formatted(this.x); }
...> }
| created class Test
jshell> var foo = new Test(0);
foo ==> Test(x=0)
jshell> void thing(Test test) {
...> test.x = 3;
...> }
| created method thing(Test)
jshell> foo
foo ==> Test(x=0)
jshell> thing(foo)
jshell> foo
foo ==> Test(x=3)
if it was pass by value, then foo would still be Test(x=0)
@privateger in java, passing a parameter to something binds it to a new name
if you assign something to that name, then you are replacing the previously bound thing. C++ references on the other hand are not bound to a new name when passed as a parameter, rather a binding to the original name is passed
this is true of both primitives/value objects and non-primitives in java. and since primitives/value objects are immutable, the only operation you can do is to assign a new instance to the name, replacing the binding.
since primitives and value objects have no identity, the JVM can choose to copy it when passing them as a parameter. however, it could also choose to pass them as a pointer if it didn't want to copy it. AFAIK, there is nothing that prevents the JVM from doing this.
@solonovamax
That jshell demo only shows mutation through a shared object. Thatâs exactly not what Iâm talking about. Both foo and test hold copies of the same reference, so changing test.x changes the object foo points to. Pass-by-value of a reference is that.
Put test = new Test(3); in thing() instead. foo stays Test(x=0). Thatâs what Iâm actually talking about.
The very Wikipedia article you linked puts Java under âcall by sharing,â and its call-by-reference section says that Java is call-by-sharing, not call-by-reference. It even uses the swap test I mentioned.
however, it could also choose to pass them as a pointer if it didnât want to copy
Sure, but that is about implementation, not the semantics. Pass-by-value vs pass-by-reference is observable behavior, and JVMs can optimize freely as long as the behavior doesnât change.
In call by value (or pass by value), the evaluated value of the argument expression is bound to the corresponding variable in the function (frequently by copying the value into a new memory region). If the function or procedure is able to assign values to its parameters, only its local variable is assignedâthat is, anything passed into a function call is unchanged in the caller's scope when the function returns. For example, in Pascal, passing an array by value will cause the entire array to be copied, and any mutations to this array will be invisible to the caller
(Wikipedia, emphasis my own)
I think the argument is that Java basically passes everything as a std::shared_ptr<T> by value.
As in, it is not true pass-by-reference, because you can only modify the object but not reassign the reference.
Exactly. shared_ptr by value is pass by value, the value just being a pointer. A raw T* by value is even closer, since Java refs arenât refcounted.
C++ references are the opposite, assigning to a T& parameter writes to the callerâs variable, which is why swap(T&, T&) works and a Java swap canât.