Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
nielsm
Jun 1, 2009



Just include Windows.h and write LPCSTR or whatever exactly it is. Or make your own semantic typedef.

The way I've heard it explained is that with "char *foo", you don't think of the type of foo as char*, you think of the type of *foo as char.

Adbot
ADBOT LOVES YOU

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


That fits how the language works but it's not natural, obvious or right.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
code:
template <typename T> using ptr = T*;
ptr<char> a, b; // both are char*
(don't actually do this)

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
Options: true/false/guest

raminasi
Jan 25, 2005

a last drink with no ice
Back when I wrote C++ and had no coworkers so I could do whatever the hell I wanted I went with the King Solomon-esque
C++ code:
char * lol;

FlapYoJacks
Feb 12, 2009
Char multiplied by lol

Spatial
Nov 15, 2007

ultrafilter posted:

That fits how the language works but it's not natural, obvious or right.
And as an added bonus it's inconsistent!

QuarkJets
Sep 8, 2008

ultrafilter posted:

That fits how the language works but it's not natural, obvious or right.

Please stop quoting comments from my pull requests

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

The real thing that throws me is that * on a value dereferences it, i.e. it changes it from address-of-T to T.

But * on a type does the opposite, it changes it from T to address-of-T.

It should be:

code:
// "foo is a variable that produces a char when dereferenced"
char *foo

// or, 100% equivalently, "foo is a variable holding the address to a char"
&char foo

Spatial
Nov 15, 2007

C is a nice language where everything makes sense and it's not too complicated.

Let's start with the numberline. Is -1 less than 1? Okay, well, you see-

lord funk
Feb 16, 2004

NihilCredo posted:

The real thing that throws me is that * on a value dereferences it, i.e. it changes it from address-of-T to T.

But * on a type does the opposite, it changes it from T to address-of-T.
I'm glad you said this because I've felt crazy ever since teaching myself to program that this didn't make sense to me.

Athas
Aug 6, 2007

fuck that joker
I teach a computer systems course at university level, and each year I have to carefully demarcate which difficulties are inherent to the domain (manual memory management, fixed-size types, programming without abstraction layers) and which are due to design flaws in C (stupid pointer syntax, weak type system, implicit casts, atrocious function pointer syntax).

namlosh
Feb 11, 2014

I name this haircut "The Sad Rhino".

NihilCredo posted:

The real thing that throws me is that * on a value dereferences it, i.e. it changes it from address-of-T to T.

But * on a type does the opposite, it changes it from T to address-of-T.

It should be:

code:
// "foo is a variable that produces a char when dereferenced"
char *foo

// or, 100% equivalently, "foo is a variable holding the address to a char"
&char foo

As someone who’s bounced off C and CPP for years and is now taking another shot at it in order to do some embedded dev, this part has caused me so many issues.
You think that it must be a problem in how you’re thinking about variables, addresses and pointers and it causes you to think you don’t “get it”
And for whatever reason, people don’t call it out. Like if I’m teaching CPP the first thing I’ll teach is this bullshit and how it’s dumb. * operator doing two totally different things like that is ridiculous. Wish I had realized it years ago and just accepted it and moved on lol.
I also think it’s stupid to try and teach pointers without teaching references hand in hand. Ughh

While I’m on a rant, c++ using << and >> operators in iostream in every tutorial is ridiculous. Like, let me put a super esoteric, advanced concept in front of people just learning the language. That won’t cause them to think it’s just magic lol

Arby’s drive thru… can I get extra horsey sauce please

ToxicFrog
Apr 26, 2008


Athas posted:

I teach a computer systems course at university level, and each year I have to carefully demarcate which difficulties are inherent to the domain (manual memory management, fixed-size types, programming without abstraction layers) and which are due to design flaws in C (stupid pointer syntax, weak type system, implicit casts, atrocious function pointer syntax).

Start teaching it in Rust :getin:

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Yeah I think a big part of why a lot of people think "pointers are hard" when first introduced is that c uses * for two different things, both pointer related. And they try to understand what * does, without it being clear that it's actually doing two different things.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

namlosh posted:

As someone who’s bounced off C and CPP for years and is now taking another shot at it in order to do some embedded dev, this part has caused me so many issues.
You think that it must be a problem in how you’re thinking about variables, addresses and pointers and it causes you to think you don’t “get it”
And for whatever reason, people don’t call it out. Like if I’m teaching CPP the first thing I’ll teach is this bullshit and how it’s dumb. * operator doing two totally different things like that is ridiculous. Wish I had realized it years ago and just accepted it and moved on lol.
I also think it’s stupid to try and teach pointers without teaching references hand in hand. Ughh

While I’m on a rant, c++ using << and >> operators in iostream in every tutorial is ridiculous. Like, let me put a super esoteric, advanced concept in front of people just learning the language. That won’t cause them to think it’s just magic lol

Arby’s drive thru… can I get extra horsey sauce please

like it's dumb but i've been writing c++ since the 90's so * doesn't even register among all the other dumb poo poo i see about the language.

c++ is one of the worst taught subjects in school to the point where it makes me suspicious of cs education in general. some people will just take c++ classes and think that they're any good at the language, or even literally put "c/c++" on their resume, when in reality you could literally write "gently caress you" on your resume as a joke and get a better reaction from me than if I see "c/c++" (and I mean literally "C/C++", it's reductive to group the two together and many C programmers would happily murder C++ programmers if given the opportunity, it'd be like putting "Israel/Palestine" as a line on your resume).

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
C's idea of "declaration follows use" was a really bad one, but it's one that you really need to introduce early because it's what makes C declaration syntax merely stupid instead of completely incomprehensible.

cheetah7071
Oct 20, 2010

honk honk
College Slice
Fortunately in C++ the number of times you want to manually declare a pointer are pretty limited. Smart pointers, vectors, and arrays cover most of the use cases of pointers while also having destructors

Of course, teaching how those work without letting learners mess around with raw pointers sounds so difficult that there may be no teaching advantage

OddObserver
Apr 3, 2009
Whatever C++ is, a good choice for an introductory teaching language it isn't.

Spatial
Nov 15, 2007

namlosh posted:

do some embedded dev

ToxicFrog
Apr 26, 2008


Yeah, my school didn't touch C++ at all -- it was C and VHDL for low-level stuff, Java and Python for everything else. Some courses also had a "you can turn in assignments in any language you can convince the TA to mark" clause, so I also got some practice with Erlang, Postscript, Lua, and Scala.

It wasn't all good (I can, for example, point at their decision not to explicitly teach debuggers or version control on the assumption that everyone coming in either is already familiar with them or can be brought up to speed by a classmate outside of class hours), but I think the call not to touch C++ in the undergraduate curriculum was a good one.

Volte
Oct 4, 2004

woosh woosh
My CS degree was mostly “here’s the language we’re using in this course, here are some links to learn it if you don’t already know it”. We did do one C++ class but it was mostly about software design concepts and not the language itself.

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
My college was all about C++ because one of the bigger profs did a lot of work on STL. I spent more time getting mad at the compiler than I did learning data structures and algorithms.

JawnV6
Jul 4, 2004

So hot ...
my worst introduction to a language was a bored TA explaining "Verilog's kinda like C without recursion" which is... a little lacking

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
I'm using Verilog right now

You could fill this thread with verilog poo poo

OddObserver
Apr 3, 2009
Is it Verilog or VHDL (or both?) that's full of language features that only work for simulation and can't actually be synthesized into hardware?

Foxfire_
Nov 8, 2010

Both do that. Using them to design a circuit needs both a language for describing the circuit and a language for saying how to test it. It would probably have been better design to make a harder line between those parts, though they do need to interact a long (i.e. "in this test, we will connect circuit A to circuit B, then wiggle input pins on A and check that the right signals come out of B")

JawnV6
Jul 4, 2004

So hot ...

OddObserver posted:

Is it Verilog or VHDL (or both?) that's full of language features that only work for simulation and can't actually be synthesized into hardware?

ive seen a Verilog tutorial "hello world" that's just that, using $display("hello world") to make the simulator print those characters

cheetah7071
Oct 20, 2010

honk honk
College Slice
I assume the correct way to teach C++ is to teach C and then, afterwards, say "you know that thing in C that was annoying/kept causing bugs? here's a C++ feature or stl class that helps with that"

I'm self-taught so all I can really say is that the results on google are very not-good at explaining which parts of the C++ language are there mostly to be backend to the stl/your own low-level classes, and which ones you're actually supposed to be interacting with on a regular basis

F_Shit_Fitzgerald
Feb 2, 2017



My experience is the opposite of everyone else's. My alma mater taught us C++ almost exclusively when I was there in the mid '10s, with a little Java here and there. I think the idea was that learning C++ would teach you the technical fundamentals of data structures (since you have to do a lot of set up and break down work yourself) before you learn a language like Java that does a lot of the grunt work for you.

I came out of my university experience a better programmer, but it's rare when I see a coding job that requires C++. Everything now is either Python or Java.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
I believe Verilog was actually designed for logic simulation first, and only later was it adapted for synthesizing hardware.

Foxfire_
Nov 8, 2010

I am happy with how my school taught.

Introductory "How to program computer?" was a school-wide required class and taught using Java (I think it is Python now).
C++ was introduced in "Intro to Data Structures" alongside the main data structure content. Everybody taking that was already familiar with imperative languages in general, and C++ is a decent tool for a class that's about stack/queue/linked list/heap/priority queue/binary tree/red-black tree/hash table/... and how to implement them/computational complexity of them. Then there was more C++ stuff in "Into to Algorithms" later.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I learned C++ as my first language but that was in 1998 so a lot of the nicer features just weren't there yet. I think there's a lot to be said for teaching pointers early on because no high level language is really successful at abstracting them away, but I don't know if a first course is the right time to do it.

Rea
Apr 5, 2011

Komi-san won.
I learned an eclectic mix of languages at college. The intro courses used C++, the courses that were basically "practical software engineering" (i.e. working in teams, Agile, sprints, etc.) used Java, our Programming Languages course cycled through various functional languages before going to Java and then letting us pick whatever for our final project (write a very basic compiler), the combined low-level/networking course started with C, moved to Python for sockets, and then inexplicably had us learn MIPS assembly, and the parallel programming course in my senior year used C. This was all from 2014 to 2018, incidentally.

Ironically, I actually learned most of my programming knowledge through bashing my head on C# on my own time.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Plorkyeran posted:

C's idea of "declaration follows use" was a really bad one, but it's one that you really need to introduce early because it's what makes C declaration syntax merely stupid instead of completely incomprehensible.
I’m always really :colbert: about this until some time later when I have to define a function pointer that returns a pointer.

I’ve gotten to the point where I just typedef everything to make Linus sad.

dougdrums fucked around with this message at 22:12 on Sep 29, 2022

more falafel please
Feb 26, 2005

forums poster

dougdrums posted:

I’m always really :colbert: about this until some time later when I have to define a function pointer that returns a pointer.

I’ve gotten to the point where I just typedef everything to make Linus sad.

I've been writing C++ since 2001 and professionally since 2006, and I long ago just resigned myself to the fact that I'm never going to remember function pointer syntax, so I google it or copy/paste an existing typedef.

Spatial
Nov 15, 2007

Doing it in two steps makes it much easier.
code:
typedef void* CallbackSig( unsigned, unsigned );
typedef CallbackSig* Callback;

cheetah7071
Oct 20, 2010

honk honk
College Slice
I especially like the syntax for calling a member function that's been passed as a pointer

code:
class A {
public:
	void memberFunction(int x) {}
};

//elsewhere in the code
void(A::*)(int) func = &A::memberFunction;

//even later
A a;
(a.*func)(5);

more falafel please
Feb 26, 2005

forums poster

cheetah7071 posted:

I especially like the syntax for calling a member function that's been passed as a pointer

code:
class A {
public:
	void memberFunction(int x) {}
};

//elsewhere in the code
void(A::*)(int) func = &A::memberFunction;

//even later
A a;
(a.*func)(5);

I especially do not like it.

Adbot
ADBOT LOVES YOU

zergstain
Dec 15, 2005

Almost all of my courses were taught using C, except the OOP course was taught in Java. There was one course where we wrote a system with a C backend and a Python GUI, and I think the for the Software Engineering courses, the groups decided on a language. We went with Python. Probably my most embarrassing thing was not being able to finish the project in my compilers course before the end. I spent too much time looking at the internals of Clang and had a fair bit of trouble handling custom typedefs and how to determine if a string was a type or an identifier.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply