All

Talk to me!

For feature requests, ideas, critiques, if you are a Reddit mod and want to become a mod on the specular community here, or just to say hi!

💬 Text me (the dev)!
2
/c/programming C by u/NightOwlDev 5 hr ago

Getting Formatting Errors Loading .C Files in Turbo C for DOS

I am having a problem with loading .c files in ye olde Borland Turbo C for DOS 2.01. .C files will display properly if I load them in any other editor on earth, under any other operating system, but Turbo C seems to ignore line feeds(?) when loading that same file into it's IDE editor. It will throw out an error about the line being too long, etc. Sincerely, Getting a Bit Annoyed in Bermuda Edit: Thanks all for your input. I found that if I loaded the file into an editor that would format it properly and then resaved it was fixed Cheers!

💬2 comments
2
/c/programming Haskell by u/code_monkey_x 5 hr ago

My Newbie Error "Could not deduce ‘RealFrac a’ arising from a use of ‘floor’ from the context: Num a"

Hi, I'm learning Haskell, and I admit I'm just playing with it right now. While I'm not a terribly experienced programmer, I do have a Bachelor's in Computer Science. My professional experience has been restricted to mostly web development in Typescript sadly. I have not touched functional programming, but this seems unrelated to functional intricacies and more me having a primitive understanding of number types. I'm playing with pattern matching and guards so maybe excuse the silly code, I'm just starting. I try loading (":l haskell_test.hs") my file in GHCi and get the following compile error "Could not deduce ‘RealFrac a’ arising from a use of ‘floor’ from the context: Num a" . I take in type Num, and floor doesn't like that general of a type, I take it? -- testing pattern matching and guards isXFactorOfY :: Num a => a -> a -> Bool isXFactorOfY 0 0 = True isXFactorOfY 0 y = False isXFactorOfY x 0 = False isXFactorOfY 1 1 = True isXFactorOfY 1 y = False isXFactorOfY x 1 = False isXFactorOfY x y | x > y = False | abs(x / y) > floor( abs(x)/abs(y) ) = False | otherwise = True I've tried replacing Num a with Real a, RealFrac a, and some other things I've seen. But I'm just poking blindly and don't actually understand the exact issue. I'd like some help understanding it explicitly rather than stumbling upon the compile-able code. I see the reference for floor is here: https://hackage.haskell.org/package/ClassyPrelude-0.1/docs/Prelude-Math.html#v:floor I guess I'm confused what it want's floor to take in, I figured any number that's an Int or Float would work. But I'm not sure how to define that the way it wants. Again sorry for the silly code. I am quite rusty and am having a rough time getting back into .... problem solving, and reading APIs and references it seems. Thank you in advance for any help or direction you give. The full compile error output is as follows: ghci> :l haskell_test.hs [1 of 2] Compiling Main ( haskell_test.hs, interpreted ) haskell_test.hs:3:14: error: [GHC-39999] • Could not deduce ‘Eq a’ arising from the literal ‘0’ from the context: Num a bound by the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool at haskell_test.hs:2:1-39 Possible fix: add (Eq a) to the context of the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool • In the pattern: 0 In an equation for ‘isXFactorOfY’: isXFactorOfY 0 0 = True | 3 | isXFactorOfY 0 0 = True | ^ haskell_test.hs:9:29: error: [GHC-39999] • Could not deduce ‘Ord a’ arising from a use of ‘>’ from the context: Num a bound by the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool at haskell_test.hs:2:1-39 Possible fix: add (Ord a) to the context of the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool • In the expression: x > y In a stmt of a pattern guard for an equation for ‘isXFactorOfY’: x > y In an equation for ‘isXFactorOfY’: isXFactorOfY x y | x > y = False | abs (x / y) > floor (abs (x) / abs (y)) = False | otherwise = True | 9 | isXFactorOfY x y | x > y = False | ^ haskell_test.hs:10:33: error: [GHC-39999] • Could not deduce ‘Fractional a’ arising from a use of ‘/’ from the context: Num a bound by the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool at haskell_test.hs:2:1-39 Possible fix: add (Fractional a) to the context of the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool • In the first argument of ‘abs’, namely ‘(x / y)’ In the first argument of ‘(>)’, namely ‘abs (x / y)’ In the expression: abs (x / y) > floor (abs (x) / abs (y)) | 10 | | abs(x / y) > floor( abs(x)/abs(y) ) = False | ^ haskell_test.hs:10:40: error: [GHC-39999] • Could not deduce ‘RealFrac a’ arising from a use of ‘floor’ from the context: Num a bound by the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool at haskell_test.hs:2:1-39 Possible fix: add (RealFrac a) to the context of the type signature for: isXFactorOfY :: forall a. Num a => a -> a -> Bool • In the second argument of ‘(>)’, namely ‘floor (abs (x) / abs (y))’ In the expression: abs (x / y) > floor (abs (x) / abs (y)) In a stmt of a pattern guard for an equation for ‘isXFactorOfY’: abs (x / y) > floor (abs (x) / abs (y)) | 10 | | abs(x / y) > floor( abs(x)/abs(y) ) = False | ^^^^^ Failed, unloaded all modules.

💬6 comments
3
/c/programming Haskell by u/CuriousExplorer99 19 hr ago

I benchmarked Cartesian product implementations in Haskell, then compared them with C

I wrote a small article around implementing Cartesian products, starting from Haskell’s sequence. The article goes through a naive Haskell implementation, a more idiomatic list-comprehension version, native sequence, then versions using Data.Vector.Unboxed, mutable vectors, runST, unsafeFreeze to try a different memory representation. The second half compares those designs with C implementations, mostly to look at what changes when the memory layout and allocation model are made explicit. The most interesting result for me was that changing representation in Haskell reduced allocations a lot without automatically improving runtime. In some cases, fusion helped a bit (no temporary indices). I’d be happy to get feedback on the Haskell side, especially the vector/ST implementations and whether there are more idiomatic or faster ways to express this. Here is the article link: https://julienlargetpiet.tech/articles/the-cartesian-product-disaster-tour-haskell-c-and-25gb-of-allocations.html If you want to share any optimizations, you can do a PR at this repo: https://github.com/julienlargetpiet/PerfLabs It will be mentioned in the next article update. PS: We now managed to find (currently) best version which is this one (in C) running at 160ms for 100k iterations to 55 lists here: https://github.com/julienlargetpiet/PerfLabs/blob/main/CartesianProduct/contrib2/contrib2.c I'm updating after trying some new Haskell impl, thanks everyone for the help and the intuition on where to dig !

💬4 comments
5
/c/programming C by u/tolwiz[ADMIN] 1 days ago

Been studying the original C compiler from 1972 by Ritchie.

Researching early Unix and low-level systems, and I ended up spending a good amount of time with this: the actual source of the first C compiler, written by Dennis Ritchie in 1972. Everything we write today traces back to this. Worth reading if you haven't... source: https://github.com/jserv/unix-v1/tree/master/src/c

💬7 comments
4
/c/programming Python by u/code_monkey_x 1 days ago

What's behind the massive boto3 download spike on Python 3.9?

I was looking at pypistats.org for the boto3 package (broken down by Python minor version) and noticed something wild — around late March / early April 2025, daily downloads tagged as Python 3.9 jumped from ~10-20M to 60-80M+, basically overnight. The spike persists and hasn't returned to the old baseline. Every other Python version stayed flat. It's exclusively 3.9. Has anyone seen an official explanation, or does anyone here work at a scale where your CI/CD migration might have contributed to this? Would love to hear what actually happened. Link: https://pypistats.org/packages/boto3

💬4 comments
4
/c/programming Presentations by u/code_monkey_x 1 days ago

Hey everyone, just joined

Hey, I’m code_monkey_x. I mostly write Python and JavaScript for practical stuff, but I’m trying to get better at Rust and OCaml. I like automation, small tools, parsers, and occasionally rewriting something three times just to understand the tradeoffs. I’m here to learn, share small experiments, and find discussions that are more substantial than the usual social media noise.

💬3 comments
2
/c/programming C by u/QuietReader42 19 hr ago

Can on demand paging be used to implement dynamic arrays?

Dynamic arrays, for instance std::vector in c++ are implemented based on the idea that if their size exceeds their capacity, the underlying array is reallocated to one that is twice the current capacity. My question is, would this even be necessary given that at least in Linux, pages are allocated to a process on demand? For instance, with a simple program like this: #include <stdio.h> #include <stdlib.h> int main() { long size = (long)(64 * 4096 * 64) * 8; long *arr = malloc(size); for(long i=0; i < (size/32); i++) { arr[i] = i; printf("%d\n", arr[i]); } printf("--->%p\n", arr); while(1) ; } if size were equal to 64 * 4096 * 64, we can see via /proc/[PID]/maps that the heap section is about 4M(despite the malloc being for 16M) and with the size given in the program it is about 32M(despite the malloc being for 128M), illustrating on demand paging. Considering that this implementation is probably not used widely, why is that? I figured one explanation would be the assumption of the system having on demand paging at all, which simply might not be the case, thus reducing portability, but what am I missing otherwise?

💬4 comments
3
/c/programming Presentations by u/NightOwlDev 1 days ago

Good afternoon, folks

Hey, I’m NightOwlDev. I started with C and still use it when I want to understand what’s happening close to the machine. These days I also write Rust for side projects, mostly small CLI tools and experiments with networking. I’m interested in low-level programming, Linux, debugging, and the kind of bugs that only show up late at night.

💬2 comments
2
/c/programming Presentations by u/CosmicExplorer 1 days ago

Hey there, happy to join

Hi, I’m CosmicExplorer. I’m into C, Rust, Linux, and mathematics. I like understanding systems from the bottom up, but I’m also interested in formal methods, programming language theory, and how we can make software more reliable. I’m here to discover interesting projects, collect good resources, and discuss technical topics with people who care about details.

💬3 comments
2

Hey there!

Hi everyone, I’m CuriousExplorer99. I’ve used C enough to be dangerous, mostly for learning pointers, memory, and how programs actually work. Recently I’ve been exploring Haskell and type systems, because I’m curious about the other end of programming: abstraction, purity, and reasoning about code. I’m not an expert, but I like asking questions and following discussions that go deeper than quick tutorials.

💬1 comments
1
/c/programming C by u/NightOwlDev 1 days ago

Async/Await in C?

The question explains itself, but for context: I am writing an Over-Engineered HTTP server for fun's and learning's sake, and I have hit a conceptual roadblock. Currently, the server works thusly: One (1) thread sits on a port and accept()s incoming requests and adds them to a queue, then pthread_cond_signal()s a condition that... ... Four (4) threads (request handlers) are pthread_cond_wait()ing on, one of whom will pick up the request and parse it. Here comes the issue: Similar to that the server simply adds each request to a queue, I want each request handler to, once it's parsed a request, hand it off to some HTTP_<method> function, then pick up the next request from the queue, only returning to the original point of execution (the point where HTTP_<method> was called), where it then returns a response. The only two ways that comes to mind of doing this, one of them require N more threads sitting on another queue, which I feel weird about, and the other requires some Macro Fuckery that I found on a Github repository then lost, so Idk if it even is feasible. How do I go forward from here? TL;DR: Async Await for C; good, bad, or disgustingly ugly? Potential other solutions?

💬4 comments
1
/c/programming Presentations by u/QuietReader42 1 days ago

Hi everyone

Hi everyone, I’m QuietReader42. I mostly read more than I post, but I’ve been programming in C for a while and I’m interested in systems programming, compilers, memory layout, and Unix-style tools. Lately I’ve also been looking at OCaml because I like the idea of using functional programming for compilers and interpreters. I’m here to follow good technical discussions and occasionally ask questions when I get stuck.

💬2 comments
Page 1
Next →

Earde

Your personal frontpage.

Talk to me!

For feature requests, ideas, critiques, if you are a Reddit mod and want to become a mod on the specular community here, or just to say hi!

💬 Text me (the dev)!