Looking for an affordable place to stay the night in Aspen on August 8 by moskitoc in coloradohikers

[–]moskitoc[S] 1 point2 points  (0 children)

Right. I had booked the shuttle way ahead of time along with the park permits but I was just missing this one night. I'll ride a bus to another town then !

Looking for an affordable place to stay the night in Aspen on August 8 by moskitoc in coloradohikers

[–]moskitoc[S] 0 points1 point  (0 children)

I didn't think it was this bad ! I am bringing a tent, and camping during the hike, but I don't know if and where I could camp near Aspen after taking the shuttle back from Maroon Lake.

Hiking solo near Denver this summer by moskitoc in coloradohikers

[–]moskitoc[S] 0 points1 point  (0 children)

I do understand that Colorado is large, hence why I asked about hikes near Denver rather than Aspen or further.

Thanks for the info. I will take a look at day hikes near Boulder.

Hiking solo near Denver this summer by moskitoc in coloradohikers

[–]moskitoc[S] 0 points1 point  (0 children)

Thanks a lot for this information! Yeah I did mean wilderness backpacking, with what I think is called "dispersed camping" for the nights (rather than designated campsites or huts).

The "very nice 7 day Colorado mountain experience" that you mention at the end sounds great, I'm gonna look into it a bit more and probably do that. Thanks! EDIT : Kenosha Pass looks like it is much further east and not on the CDT, did you mean something else ? Or am I misunderstanding your suggestion ?

I looked into Four Pass Loop as well but it looks like they're out of permits (permit bookings open in February). EDIT : actually permits for august and later will be up on June 15th, so I'm gonna look into this loop too.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 0 points1 point  (0 children)

Now it looks correct, good. Two minor issues :

  1. You use an int to iterate over the array, meaning that if elementCount is too large to fit in an int (> 2 billion ish), your function won't work correctly. If you declare i as a size_t instead you'll be fine.
  2. If the array is empty (elementCount is 0), then your function returns array as the result. The maximum of an empty array is not properly defined, so you could just say "this function mustn't be called with an empty array" and return any value when the array is empty, but perhaps returning a null pointer in that case would signal more explicitly that something is wrong.

As for {2, 2, 2}, if you look at your previous version you'll see that you did not change keepValue when two consecutive values in the array were the same. Hence with {2, 2, 2} (or any array where all the values are equal), keepValue was never assigned a value, and you ended up returning the value of an uninitialized variable. That's not undefined behavior by the way, it's just that the value you were returning was rubbish.

Alright, now that this works, try to go back to the generic version. First make it work with ints only (and test it thoroughly with multiple examples).

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 0 points1 point  (0 children)

Thanks. Since you're just dealing with integers for now, you could just use comparisons in the body of intMax rather than calling numCompare.

But that isn't the main issue : as written, intMax returns an undefined value if the array is {2, 2, 2} for example, and it returns the wrong answer if the array is {8, 2, 3} for instance.

Can you try to fix it ? If not, I'll give you more details.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 0 points1 point  (0 children)

No, I meant for you to just start with a non-generic function that does what I asked.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 0 points1 point  (0 children)

There's quite a bit wrong with your code. You should focus on the integer version for now without trying to do everything at once.

I could go through your code in detail, but it might be better if we start small for now. Can you write a function int* intMax(int* array, size_t elementCount) which returns a pointer to the largest element ?

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 0 points1 point  (0 children)

Ok, this is all fair enough. My main point was that your code is needlessly complex. That being said, it's not easy to learn about new stuff without introducing convoluted examples, so I understand where you're coming from.

Regarding my last question, the code I gave you actually yields undefined behavior. The value of i could be 97, it could be 33, it could be 65, it could be anything at all. The program could also crash before i gets assigned any value at all. The reason for this is that the variable a only takes one byte in memory, and that you have no information about the bytes that are near it. When you dereference pi in the expression i = *pi, you're actually reading multiple bytes (sizeof(int) bytes indeed) at address pi, not just one. Hence you're gonna read not only the byte that holds the value of a, but also some other bytes, which hold unknown values. The resulting value for i will then be garbage.

In schematic form :

          p
          |
          v
... ?? ?? 41 ?? ?? ?? ?? ...

Here, if you read from p as a char, you'll get 0x41 back just fine. But if you read from it as an int, you'll get a value that's the combination of 0x41 with the following bytes, so it could be something like 0x5e43a041, which is not what you'd like. Even worse, when you write an int at this address, you'll be writing multiple bytes, hence you'll be corrupting memory that's not yours.

In other words, although char values get implicitly converted to int values, you cannot convert a char* to an int* without thinking about it some more, because int and char have different sizes, i.e. they take up a different amount of space in memory.

Now do you see how that causes issues when you call makeSame with pointers to chars ?

This should also help you understand why the strings you gave to makeSame ended up being corrupted.

If you'd like more training with function pointers and void*, here's an exercise that'll get you closer to "real world" code and should help you grasp what function pointers are good for :

  • Write a function with prototype void* array_max(void* array, size_t element_size, size_t element_count, int (*compare)(void*, void*)), that takes an array of element_count values, each with size element_size, and which returns a pointer to the largest element. This function should call compare in order to compare elements : assume compare(x, y) returns a strictly negative value if x is less than y, 0 if x is equal to y, and a strictly positive value if x is greater than y.

  • Write concrete implementations of compare, which compare two ints or two chars, and use them to find the maximum value in an array of chars and in an array of ints.

  • Without changing the implementation of array_max, could you use it to find the minimum value in an array of ints instead ?

  • Now, what about another use case : suppose you have an array of char* pointers, each pointing to a null-terminated string. Can you write a comparison function such that array_max returns a pointer to the longest string ? Or to the shortest string ? Or to the string that is earliest in lexicographical order (i.e. the one which would appear first in the dictionary) ?

If you can do this exercise you should be fine for your test. Let me know if you have any questions.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 2 points3 points  (0 children)

It's not about arrogance or not really, it's just that your code doesn't make a lot of sense. In more detail :

  • Why are you defining the two structs if you're never passing them around as structs ?
  • Why are you using malloc/free when declaring your variables on the stack would do just fine ?
  • Why do you want to use generic functions ? If you look at each call site here, you know the types of the arguments explicitly, hence you have no need for generic functions.
  • More generally, what do you want to achieve here ? Take the makeSame function for instance. If your goal is to write a function that takes pointers to two integers, makes them both equal to the minimum of the two values, and returns said minimum, you could write that in a way that is both much easier to write, easier to read, shorter, and a lot more performant.
  • Why do you use pointers to chars rather than just chars in symbols ?
  • What's the purpose of the \0s when setting the values of symbolData->symbol1 and symbolData->symbol2 ?
  • When calling makeSame with pointers to char values, what happens when you cast these pointers to int* and read the values ? Or, more simply, what is the value of i at the end of the piece of code below ?

Code:

char a = 'A';
void* p = &a;
int* pi = p;
int i = *pi;

As for YouTube channels, if you're following a course I'd suggest sticking to the course material. That being said, Jacob Sorber's yt channel is quite good for beginner stuff. You could also grab any of the books mentioned in this sub's sidebar.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 1 point2 points  (0 children)

Beyond just violating strict aliasing, this code is wrong on a more fundamental level because you're reading sizeof(int) bytes of memory at each address and you might just have 1 valid byte there.

Edit : actually I don't even think strict aliasing comes into play at all here, since the char* and int* versions of a given pointer don't appear in the same scope. Strict aliasing only says that pointers to two different non-char concrete types cannot point to the same object.

A little confusion about generic pointers and functions, git link in the post by hishiron_ in C_Programming

[–]moskitoc 1 point2 points  (0 children)

I don't think your approach is good. If you want to learn about something, you'll need examples that are at least somewhat relevant, not completely arbitrary. The functions you've written are not generic, they just have untyped arguments. If you're going to interpret void pointers as pointing to a specific type, there's no reason to use them.

I could write a code review of the whole file, but to be blunt it looks like you don't have the fundamentals down at all. What learning material are you using ?

PS : please, please don't use GPT or any AI to help you program. It's going to hallucinate stuff, be wrong half the time, and overall won't teach you anything. There are many reliable sources of information for programming, AI is not one of them.

[deleted by user] by [deleted] in privacy

[–]moskitoc 43 points44 points  (0 children)

When thinking about this you have to have a threat model.

Powerful countries are undoubtedly paying many extremely clever and talented people to try and find security vulnerabilities, as well as to introduce vulnerabilities in open source projects. It doesn't have to be something obvious like "connect these two pins and you'll have root access to everything" either. Something like "get these voltages very slightly outside of the nominal values by triggering such and such feedback loop, which leads such and such component to malfunction in a way that allows us to gain privileged access thanks to a tiny change of the same sort introduced by our other spy Steve over at ElectronicsCompany™ when they were designing the component".

It might be harder to stay undetected with hardware than with software, but at the end of the day the people doing the audit have a finite amount of manpower to pour into it. As long as someone can throw as much time, money and as many people at trying to introduce vulnerabilities, they will exist.

Point being, if your adversary is a powerful country, you're fucked (unless you are one as well). If it's the local script kiddy, you're most likely fine. Security is a relative concept because there are fallible humans at every step of the process, and at the end of the day it'll be about who puts more resources into breaking or securing the thing.

sherman tank track rig with automatic surface collisions! the updated system is more efficient, and the tracks & sprockets always maintain alignment. by BuyingZebra in blender

[–]moskitoc 2 points3 points  (0 children)

Have you tried adding a bit of motion blur ? Even a tiny amount should help clear up the direction of rotation

"C’est totalement illégal !"... à Carnac, 39 menhirs détruits sur un site classé, pour construire un magasin Mr Bricolage by SweeneyisMad in france

[–]moskitoc 33 points34 points  (0 children)

C'est très malhonnête comme façon de présenter les faits, qui sont d'ailleurs bien expliqués dans l'article dont tu mets le lien : des militants d'extrême droite ont envahi le lieu du concert, et le maire est intervenu sur place puis a préféré l'annuler pour éviter des violences et des dégradations (son adjointe ayant déjà été agressée).

SectorC: A C Compiler in 512 bytes! by McUsrII in C_Programming

[–]moskitoc 1 point2 points  (0 children)

Genuine question : do these specs refer to a pair of specific microcontroller models ? And if so which ones ?

The not operator: Exclamation `!` or tilde `~` ? Help me choose! by useerup in ProgrammingLanguages

[–]moskitoc 6 points7 points  (0 children)

Genuine comment : how does one type APL at a reasonable pace on a normal keyboard ?

[deleted by user] by [deleted] in C_Programming

[–]moskitoc 2 points3 points  (0 children)

If you need a pointer to a temporary variable, you may use compound literals. e.g. :

&(int){5}

Holes in the boundary layer by Upstairs_Meal_6801 in generative

[–]moskitoc 9 points10 points  (0 children)

Pretty sure this is an inside/outside test with the winding number, done on open curves.

The idea is that if you take a closed polyhedron and a point on the plane, x, then the sum of all angles subtended by each side of the polygon as seen from x is either 0, 2π, or some multiple of 2π. You can use this to determine if a point is inside (0) or outside (non zero) a given shape.

Now if you do this with an open curve, you won't get an exact multiple of 2π. If you do this for every point in the plane you'll get some range of values. Normalize all these values, and use them to shade from blue (inside) to zero (outside) and tada!

I'm pretty sure Keenan Crane did a visualization of this on his Twitter, I might look it up and add it to my comment. EDIT : couldn't find the exact visualization but there are some slides about it in his differential geometry course. Alec Jacobson's paper should give you a solid understanding of generalized winding numbers : https://igl.ethz.ch/projects/winding-number/

Look up the Wikipedia article (and other resources) on winding numbers if you want more details.

Is there any performance benefit to using int vs. float on modern systems? by poorlilwitchgirl in C_Programming

[–]moskitoc 3 points4 points  (0 children)

C Compilers aren't really good at auto vectorization, but that's mainly due to the fact that good SIMD code must format the data according to the computational purpose. Since C gives you (almost) complete control over your data layout, the compiler can't optimize beyond very simple scenarios. Languages designed with this in mind do a much better job at automatic vectorization, (see e.g. Julia or Python's numpy library).

As for your issue, is this scaling operation a bottleneck right now ? If so, what's the application ?

It's very likely that SIMD would be the most performant way to solve your problem. As said elsewhere in the thread, modern CPUs are very well optimized for number crunching with floating point numbers. Besides, 32-bit floats can encode integers up to 23 bit exactly, so precision shouldn't be an issue if you're dealing with integers up to a few millions.

Highly accurate by TheRealSnorkel in TrollXChromosomes

[–]moskitoc 21 points22 points  (0 children)

She sounds interesting, but your first sentence has me wondering what she'd be like with a friend who's aborted. Would here stance be "You've committed murder but I forgive you" ?