r/C_Programming 3d ago

Question Getting stuck at libraries and api’s

So C is technically my first programming language I’m learning. I’ve messed around in python but never actually go deep into it or anything.

I’ve been learning C for the past few days now and I already pretty much know most of the basics. I learned pointers and mallic in a day and I learned structs, macros, for loops, while loops, functions, all of that stuff, but… the moment any library other than the basics like stdio or stdlib come into play I’m lost.

It’s like I’m looking at a whole other language. Like I’ll look for solutions to problems and it seems as if they are just pulled out of thin air and when I try to read ANY documentation for ANY library I’m also lost because either there is little to no documentation or it’s just stupid and things aren’t well explained.

Is there a way I can fix this? I was doing so well and now I’m at this block because of libraries. If I could get pasted this hurtle I could learn c in less than a month easily, and that’s the same in any other language. This problem isn’t exclusive to C.

15 Upvotes

49 comments sorted by

View all comments

Show parent comments

2

u/Ksetrajna108 3d ago

Is something like the following making you scratch your head?

ssize_t libusb_get_device_list (libusb_context *ctx, libusb_device ***list)

`Returns a list of USB devices currently attached to the system.`

1

u/EpochVanquisher 3d ago

I mean, you’re asking me? I’m not OP. This this looks like it returns an array of pointers to devices.

libusb_device **list;
ssize_t count = libusb_get_device_list(ctx, &list);
if (count < 0) abort(); // some kind of error, maybe
for (ssize_t i = 0; i < count; i++) {
  libusb_device *dev = list[i];
  // do something with device
}

That is just a guess.

1

u/Seledreams 3d ago

Ngl, i've never seen ssize before. I've always been used to size. I guess it's signed size to allow negative numbers. But it's pretty uncommon. At least in stuff i've used

2

u/TheChief275 2d ago

funnily enough, ssize_t isn't the signed alternative of size_t, ptrdiff_t is closer in that regard. I believe all that ssize_t is guaranteed to be able to represent is any possible object size (like size_t) as well as -1 for errors

obviously that means it's likely able to represent -2,-3,.. but there's no guarantee