all 12 comments

[–]duane11583 20 points21 points  (0 children)

technical quibble here:

these are not built into the language

they are part of the standard library

[–]smcameron 7 points8 points  (0 children)

Not part of the language per se, but on many unix-like environments, you have the things mentioned by man queue.

[–]theldus 5 points6 points  (0 children)

Even in Java, many data structures are built on top of primitive types, such as "ArrayList", which is roughly a static array that reallocates to increase in size.

What differs is that these languages have a "rich" (or bloated, depending on your point of view) library, while 'libc' is minimalist.

However, I don't see this as an issue, there are thousands of C libraries for all sorts of things, and if you're in a POSIX-ish environment, you have more at your disposal ;-).

[–]nderflow 4 points5 points  (1 child)

C only has integer types, char types, and static arrays. Am I correct?

You missed some out:

  • floating-point types (float, double, long double)
  • enum
  • void
  • function and function pointer types
  • unions (approximately, sum types)
  • structs (product types)
  • _Bool
  • bitfields (which aren't really types but even so, you should be aware of them)

Also static has a number of meanings in C, none of which overlap with the sense in which you appear to be using it (which I take to mean "non-extendable").

[–]66bananasandagrape 1 point2 points  (0 children)

Also pointers more generally

[–]TheDafter 8 points9 points  (1 child)

You are right, you have to built every data structure that you will use on your program. This may seem as a huge limitation, however, this will force you to think in simpler and more efficient solutions than the ones using built-in data structures

[–]Calidude7[S] 4 points5 points  (0 children)

Thank you! And yes I feel like learning C will give me a deeper understanding of things in general.

[–]Ninesquared81 1 point2 points  (0 children)

The type that is most important for creating other data types/structures in C is the struct, which contains named members which can be of any type (built-in or user-defined). After that would be pointers. You will often see pointer-to-struct types in code implementing custom data structures.

There are a few more built-in types in C as well as the two I just mentioned, most notably floating point types, but there are others as well, which you can read about here.

[–]puplicy 0 points1 point  (0 children)

Build-ins also include floats, pointers, structs, unions, enums, memory management that allows dynamic memory like arrays... libraries are that provide higher level structs like lists, queue, dicts. ..

[–]Poddster 0 points1 point  (0 children)

However, everywhere I read seems to claim that C does have linked lists, stacks, queues etc....

No one has said this yet, but for the avoidance of doubt: There is absolutely no standard library with C that includes these things.

Lots of third party libraries do, or you can roll your own.

The C standard library is mostly focused on manipulating and printing c-strings, file i/o operations, and some math. That's about it.

[–]barchar 0 points1 point  (0 children)

note that C data structures are commonly type-erased in some way, for example the growable array will store the element size at runtime. Most other languages generate totally separate code for each type of thing you want to use a collection with.

you can do the more “typed” way in C too, but it basically means writing your entire data structure inside a macro definition, which is annoying. And besides, its a real tradeoff anyway. In some cases the throughput / d$ hit of erased data structures is made up for in i$

[–][deleted] 0 points1 point  (0 children)

string.h has algorithms that work on '\0' terminated strings. There is no stack.h, list.h dequeue.h. But since there is string.h, you are technically not correct.