[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1720653677648032.jpg (32 KB, 432x324)
32 KB
32 KB JPG
What are you working on, /g/?

Previous thread: >>107456434
>>
Rewriting my Rust projects in C.
>>
File: 1716676023388469.jpg (408 KB, 2048x1918)
408 KB
408 KB JPG
#include <stdio.h>

int main()
{
printf("goodbye world\n");
char array[8 * 1024 * 1024];
return 0;
}

this silently fails on x64 and segfaults on arm, it caught me out yesterday when writing a quick program to concat some files
>>
File: chrome_b5z1wgpO1B.gif (2.27 MB, 1203x661)
2.27 MB
2.27 MB GIF
Made an avatar cropper for the "communities" feature of my site. Basically something similar to discord communities except for an image board, so people can create private boards with their own posts/tags/etc.

Needed a way to upload banners for it, so built this out. All vanilla js + golang/ffmpeg on the backend to encode and crop the images.
>>
>>107495237
Try increasing increasing the maximum size of stack segment to 16 MiB
ulimit -s 16384

This setting seems to apply per shell instance.

>silently fails
Are you using compiler optimisations?
>>
File: program_layout_in_memory.png (277 KB, 1988x1440)
277 KB
277 KB PNG
>>107495237
That's because your array is too big too fit (it's 8MB) on the stack on most Linux systems (the default stack size is 8MB so you are kind of there at the limit). I think the stack is even smaller on Windows but not sure.
Do dynamic memory allocation if you want big arrays.
>>
>>107495237
learn to cal mmap
>>
File: haskell_uh_no.png (608 KB, 1893x806)
608 KB
608 KB PNG
>>107494948
Based
>>
>>107495237
You should asume the system has a large stack (16k is safe), sir. But in the case of the code you posted that char array is optimized out by the compiler. Just use an static array or dynamic memory.
>>
>>107495681
>people can create private boards with their own posts/tags/etc.
you mean blogs?
>>
>>107495760
That picture is oversimplified. When you have several threads, you can have stacks in your stack, so you can push while you push.
>>
>>107495867
This particular feature is for a feature similar to discord servers, where you can create your own community to post blogs/images/videos/etc to.

Those posts can be tagged, but the posts are specific to the community itself. Post feature was already working, but on a single unified site.
>>
Does anyone need help with debugging code or doing homework? I can program for food.
>>
>>107495681
>Basically something similar to discord communities except for an image board, so people can create private boards
Interesting, I'm doing something similar.
Currently planning how to implement group-based permissions. I already have threads, accounts, and file uploading.
>>
>>107496505
I can also crack software.
>>
>>107496352
i don't use dicksword
what you're describing sounds just like a blog
>>
>>107496505
>>107496550
Please, chuds. I need to eat.
>>
>>107496536
perms are always a pita.

Good luck brave soldier.
>>
I have a hash table that is growing too big and I think I will have to implement it in storage memory instead of ram memory. Is there any specific algorithm that would be good for this? I could use sqlite but maybe there is something better that is less generic and more application specific.
>>
>>107498050
CDB
https://en.wikipedia.org/wiki/Cdb_(software)
https://www.unixuser.org/~euske/doc/cdbinternals/index.html
>>
File: cdb.png (5 KB, 699x359)
5 KB
5 KB PNG
>>107498260
>>
File: 1547675359680.jpg (66 KB, 372x360)
66 KB
66 KB JPG
>>107494927
Trying to really understand the phi function and where it fits into my compiler
>>
File: Captcha.png (4 KB, 305x126)
4 KB
4 KB PNG
just got this captcha
>>
>>107498050
>didn't mention what kind of data he's storing in the table
>>
>>107495773
Not really, I'm just so tired of pointless pedantry and being told that I am the problem and gaslighted with segfaults.
Sorry, but my code does not generate segfaults like ever, maybe (You) are the problem, rustrannies?
>>
File: 1763826654868335.png (367 KB, 1280x720)
367 KB
367 KB PNG
>>107498756
Block parameters are easier to reason about than phi nodes
>>
I want to do programming as a career. I just did it as a hobby for a while. Any advice like roadmaps and startups? I'm gonna check youtube.
>>
>>107503098
it's a really shitty job path. I don't recommend
>>
File: mfw.gif (78 KB, 200x200)
78 KB
78 KB GIF
>>107503122
>shitty
>the implications
not him to be desu
>>
Is there a tool that allows you to show all the code associated with the current file/cursor? If I click inside a function it should show all the types and function definitions on a side bar in real time, recursively expanding as I scroll down.
>>
File: 1548897321647.png (129 KB, 489x424)
129 KB
129 KB PNG
>Doing some fairly quick and dirty shortest-path shit on a 6000x4000 image of a map
>Python, because I'm lazy and this is fairly throwaway code
>Dijkstra’s where every pixel is a node
>Seems like this is going to take like 4 hours to run
Fuck, I think this could be implemented about 1000x quicker I bothered to try, but I have to keep telling myself I only need to do this once, and that'll take longer than just waiting.
>>
>>107503324
How are we supposed to know when you didn't even tell us the language?
>>
>>107503443
Bump.
>>
LangDev here I come
>>
>>107503443
If you knew of any such tool for any language you would reply with that. But you don't, so you're non-contribution is useless in any case.
>>
File: 1764168070506883.jpg (2.23 MB, 3984x2988)
2.23 MB
2.23 MB JPG
>>107503706
>seq
prepare for a world of pain
>>
jaisisters...
>>
File: 1763858235184894.jpg (696 KB, 500x2035)
696 KB
696 KB JPG
>>107494927
TCP/IP sucks, UDP sucks, OSI sucks
>>
>>107506295
How would you make it not suck?
>>
>>107506358
By making information more accessible, IP addresses act as routes, while TCP ensures the quality of delivery.
>>
>>107494927
I'm going to be diving into paging and nobody can stop me from creating my kernel. Not even god himself.
https://cdrdv2-public.intel.com/868137/325462-089-sdm-vol-1-2abcd-3abcd-4.pdf
>>
>>107506446
Get to work fixing the internet.
>>
>>107506295
You are retarded.
>>
>>107507390
Why?
>>
>>107507457
There's nothing wrong with either protocol, infrastructure is simply shit, especially in turd world and on the borders with Russia
>>
>>107506295
After the snowden stuff there were proposals for a more private and significantly faster transport layer called fasttp from memory, there was a paper on it
>>
>>107494927
>What are you working on, /g/?
Debugging memory corruption.
>>
>>107494927
Are his legs ++ in this one. I'm not sure I've ever seen the original
>>
File: 1716497693623529.jpg (48 KB, 473x505)
48 KB
48 KB JPG
>>107508942
>>
>>107503706
>(let var expr) statemenet
nice, already an improvement over lisp
>.lisc
what does it mean?
>>
File: file.png (309 KB, 1857x895)
309 KB
309 KB PNG
>>107509024
>AI agrees
lol
>>
>>107497839
Please, chuds. I will fix your code for food.
>>
i hate c#, i'm learning c++
>>
I have started working out and wrote this to set a pace and also keep track of my pace.
>>
File: 1764396976449388.png (207 KB, 600x600)
207 KB
207 KB PNG
>>107509070
(let var expr) is a mistake as it permits y to be free in (let x y), so seq MVST be further complicated with scope information. (let var expr expr) introduces scope at the point of binding so you'd write
(let i 5
(let j 7
(let sum (+ i j)
(print sum))))

don't do it bro
>>
>>107509655
Why? What's wrong with C#?
>>
>>107509902
>(let var expr) is a mistake as it permits y to be free in (let x y)
I don't get it. In a traditional lisp, in
(let ((x y))
// do something with x
)

y is also a free variable.
>>
>>107509963
y is free in (let x y x) as there's no enclosing let, and y is free in (let x y), imagine your next step as a compiler
>>
File: LongCatIsLong.png (243 KB, 603x324)
243 KB
243 KB PNG
>>107509095
>>
what paradigm do you guys use for file parsers?
for me i typically ask if i need to mutate it or just read from it

>if mutate
then i just eager load the entire thing (so copy or initialize field by field) into some high level structure for ease of working with in the lagnuage. This is obviously terribly slow if someone just wanted to read.

>If read
then i usually build a lazy parser above a mmap buffer but with a constructor option to eager load the entire thing if desired. This is the fastest but you cant really mutate it because the lazy loaders state becomes invalid. Even if you only eager load the mmapped file a direct memory buffer is more difficult to mutate than a clean object structure.

I was wondering if there is a hybrid approach that gives you both fast performance when all you want to do is quickly read part of a file, but still allow you to easily mutate & reserialize it afterwards.
Have any /g/tards thought and perhabs solved this problem before?
>>
Converting to and from ASCII is probably the biggest waste of energy in computing right now.
>>
>>107511305
Converting to what? ASCII <-> UTF-8 is literally free...
>>
>>107511346
The only obvious case where it runs a lot of code to do the conversion...
>>
>>107511356
What conversion are you even talking about?
Is this some shit about retarded platforms like Windows and Java using UCS2/UTF-16, or some hyper-retarded complaint about decoding ASCII into actually printable characters?
>>
>>107511164
copy-on-write paradigm works well in c++ with const overloads
(consider this pseudo code)
class FileFormat
{
char* mmapped_buffer;
std::vector<Field> mutatedFields;
std::map<size_t, size_t> mutatedFieldsMap;

public:
Field& GetField(size_t n)
{
if(mutatedFieldsMap.find(n) == mutatedFieldMap.end())
{
mutatedFields.emplace_back( Field{ mmapped_buffer + (n*sizeof(Field))} );
mutatedFieldsMap[n] = mutatedFields.size()-1;
}

return mutatedFields[mutatedFieldsMap[n]];
}

const Field& GetField(size_t n) const
{
return mutatedFieldsMap.find(n) != mutatedFieldMap.end() ?
mutatedFields[mutatedFieldsMap[n]] :
static_cast<Field&>(*(mmapped_buffer + (n*sizeof(Field))));
}
};

still a tiny bit slower than just mmap & read, because reading has to lookup if a field has been mutated but you can now define much higher level structures as fields that would otherwise be difficult to mutate with just a mmapped buffer
>>
>>107511450
AFAIK Windows has some support for UTF-8, sir.
>>
>>107511164
I've never once been in a situation where:
1. I need to read and _might_ write to a file
2. The file I/O is actually important to the program
>>
>>107509024
C--
>>
>>107512419
its because i was thinking of writing a library for working with certain kinds of file formats (as i learn them). Personally i agree i've never really needed both fast reading and writing at the same time, thats why i usually just implement one of my two paradigms based on what i need but this time its supposed to be a library and i cant tell what the user of it might want to
so im just trying to make it as fast in any case.

But this Copy on Write approach might be what im looking for
>>
Is it possible to use A* to find multiple paths at the same time?
I have like 30 places on a map, and I want to know the shortest path between all of them, and I'm trying to figure out how to reduce a bunch of duplicate computations.

Or do I just go with Dijkstra’s and accept I'm going to search the entire graph like 30 times?
>>
>>107511164
>what paradigm do you guys use for file parsers?
which file formats?
>>
>>107513413
say ELF, PE, GIF, PNG, ZIP
>>
Does troonlang support variable length types?
I want to create a rather large 2D array, and I really do care about the memory layout.
let state: Box<[[u32; width]; height]> = ...; // Complains
let state: Box<[[u32; width]]> = ...; // Still complains
let state: Vec<Vec<u32>> = ...; // Retarded

Yes, I know I can use a 1D array and just calculate the offsets myself, but I'm wondering if this language can do something that C has been able to do since the 90s.
>>
>>107513281
It was a long time since I did A* in school, but IIRC typically you terminate the algorithm once you've found a path. I guess you could not do that and just keep going from that state to let other branches eventually find their way to the target. Not exactly sure of the details of how that would work.
>>
>>107513281
>>107514394
>I have like 30 places on a map, and I want to know the shortest path between all of them,
Oh, and I might have misunderstood what you're trying to do. Are you actually trying to solve the travelling salesman problem?
https://en.wikipedia.org/wiki/Travelling_salesman_problem#Computing_a_solution
>>
>>107514165
const W: usize = 16;
const H: usize = 16;

fn main() {
let fixed_h = Box::new([[0u8; W]; H]); // Box<[[u8; W]; H]>
let unsized_h = vec![[0u8; W]; H].into_boxed_slice(); // Box<[[u8; W]]>
let dynamic_h = vec![[0u8; W]; H]; // Vec<[u8; W]>
}
>>
>>107514433
>const
Good one.
>>
>>107514450
Post the C code you are referring to then. AFAIR C does not support having dynamically sized 2D arrays.
>>
>>107514462
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
int w = argc > 1 ? atoi(argv[1]) : 10;
int h = argc > 2 ? atoi(argv[2]) : 20;

printf("%d * %d * sizeof(int) = %zu\n", w, h, w * h * sizeof(int));

// On the stack.
// Lots of people complain about this specifically and how
// "dangerous" it might be, but I think it makes sense in
// very specifiic siations.
int arr1[h][w];

printf("sizeof(arr1) == %zu\n", sizeof arr1);

// On the heap.
// This has none of the disadvantages as the stack version.
// The compiler just handles the offsets properly; it's
// truly a 2D array in all respects.
//
// The only issue is that this can't exist in global/static
// contexts, so can't be put directly inside of a struct without losing type information
int (*arr2)[w] = malloc(sizeof *arr2 * h);

printf("malloc_usable_size(arr2) == %zu\n", malloc_usable_size(arr2));

free(arr2);
}

10 * 20 * sizeof(int) = 800
sizeof(arr1) == 800
malloc_usable_size(arr2) == 808
>>
>>107514611
Well, I wouldn't create "rather large" 2D array on stack.
You need to make your own structure explicitly anyway, there is no compiler magic that will do it for you.
I would personally write my own structure that holds width, height and vec, and some extra structures for "array views" which can hold strides in order to archive 2D slices like arr[1..10][2..20]. There is probably many crates that do this already but it's also not hard to make one yourself.
However if you want to archive same thing as your C code, it can be done using unsized structure.
#![feature(ptr_metadata)]
#![feature(layout_for_ptr)]
#![feature(thread_local)]

use std::{ptr, alloc};
use std::alloc::Layout;

#[repr(C)]
#[derive(Debug)]
struct Array2D {
width: usize,
data: [i32],
}

impl Array2D {
fn new(width: usize, height: usize) -> Box<Array2D> {
let len = width * height;
let ptr: *const Array2D = ptr::from_raw_parts(ptr::null::<u8>(), len);

unsafe {
let layout = Layout::for_value_raw(ptr).pad_to_align();
let ptr = alloc::alloc(layout);
if ptr.is_null() {
alloc::handle_alloc_error(layout);
}

let (address, _) = ptr.to_raw_parts();
let ptr: *mut Array2D = ptr::from_raw_parts_mut(address, len);

(&raw mut (*ptr).width).write(width);
(&raw mut (*ptr).data as *mut u8).write_bytes(0, len * size_of::<i32>());

Box::from_raw(ptr)
}
}
}

static mut STATIC_ARR: Option<&'static Array2D> = None;

fn main() {
let arr = Array2D::new(10, 20);

println!("{}", size_of_val(&*arr));

// it can be referenced in a struct!
#[derive(Debug)]
struct Wrapper<'a> {
arr: &'a Array2D,
}

let wrapped = Wrapper { arr: &arr };

println!("{:?}", wrapped);

// In a static too!
#[allow(static_mut_refs)]
unsafe {
STATIC_ARR = Some(Box::leak(arr));
println!("{:?}", STATIC_ARR);
}
}
>>
>>107514611
>>107514988
Also
(&raw mut (*ptr).data as *mut u8)
line could be skipped if you use alloc::alloc_zeroed instead.
One slight benefit of this over malloc approach is that you get to allocate the structure using it's actual aligment instead of being limited to std::max_align_t
>>
Also I don't think #[repr(C)] is even needed anymore. Layout::for_value_raw should handle everything correctly using Rust repr as well.
>>
>>107495681
Oh my God, this guy recreated Reddit.
>>
>>107511495
why not use unordered map
>>
>>107515214
yeah an unordered map would be better
i just wrote this quickly to illustrate
>>
>uses language designed to make it harder for you to shoot yourself in the foot
>complains that it's hard to shoot yourself in the foot, unlike in other language that has had foot shooting feature since the 90s
>>
>>107503422
>python
>is gonna take like 4 hours to run
LMAO
6000x4000 isn't even that big
It's 24,000,000 pixels. Your processor is capable of 4,000,000,000 instructions a second. That's 14,400,000,000,000 instructions in 4 hours. That's 600000 instructions per pixel
Holy fuck python is shit lmao
>>
>>107503422
try using numpy to accelerate it
>>
I was thinking, SWE in 3rdie countries is all about training work force. Whereas in 1stie countries like the Great Satan, they mostly study CS, which is more theory-centeric.

That is why the slumlords of Silicon Valley are so anti-college. They don't want pansy-ass Scheme-writing workforce who think for themselves. They want chad, JS-writing drones.

But they could always donate shitllions to American universities to accept more SWE students, instead of CS students.

In my 3rdie, no private college offers CS. They all offer SWE, but none offer CS. Even IAU which is a 'special' kind of private college (Walmart of colleges) rarely offers CS.

I don't think the US is doing itself any favors by training a lot more CS graduates than SWE graduates. Just compare my SWE curricula with the US Compsci curricula: https://pastebin.com/DqxdrbPH

This college calls me, and hangs up on me when I answer. They want me to go back and pay them tuition. I don't have any money, fuck off. I wanna take the national entrance exam, and see if I get accepted into a *real* CS program at a state college (aka 'real' university).

Anyways, I don't know just *why* the US is the only 1stie country, or in fact, the only country amongst 1stie and 3rdies, where Compsci is far more popular than SWE, but it cannot be good. In CS, they teach you the science of computation, not how to write web programs!

Not so quite coincidentally, the US is the only country, 1stie or 3rdie, where a degree does not really "speak" when it comes to hiring workforce. In all other countries, a degree is very important.

It's no surprise they hire pajeets, because at least, with a jeet, you'd know he's gone to college.
>>
I'm planning on implementing ECMAScript and I plan on using Shiyanhui's libcsp to implement Golang-style CSP concurrency:


// BAD: Deadlock
const ch = new Channel();

go(function*() {
yield ch.send(1);
yield ch.receive(); // Blocks forever
});

// GOOD: Use select or separate goroutines
go(function*() {
yield ch.send(1);
});

go(function*() {
yield ch.receive();
});


I had a dossier made, but I need to make more. This sucks.

I call it "DocileJS" because it's no longer "Mobile" code.
>>
I was trying to learn how to use the make tool, but everyone explains it in a confusing way, and make doesn't make any sense to me.
So I just created a program that compiles. I don't know if it's the right way to do it, but at least it works:
#include <stdio.h>
#include <windows.h> // no standard

#define MAX_READ_LINE 256

int main(int argc, char* argv[]) {
// make.txt contains the compiler's name, flags and files
FILE* file = fopen("make.txt", "r");
if (file == NULL) {
fprintf(stderr, "Error: failed to open make");
return -1;
}

char read[MAX_READ_LINE] = {'\0'};
while(fgets(read, MAX_READ_LINE, file)) {}

fclose(file);

system(read); // send command

return 0;
}
>>
>>107516578
Check out Chris Wellon's tutorial on portable Makefiles:

https://nullprogram.com/blog/2017/08/20/

Chris is the only reason I had a Reddit account. He's the most knowledgeable person on C.
>>
>>107516595
Thanks!
>>
File: achscheisse.jpg (73 KB, 1242x640)
73 KB
73 KB JPG
>>107516578
Don't worry, I won't bother explaining.
release: build/release/a.out
debug: build/debug/a.out

.PHONY: clean
clean:
@git clean -dfX

.PHONY: asm
asm: build/release/a.out
@objdump -S -M intel --disassembler-color=on $^ | ${PAGER}

override CFLAGS += -MMD
override CFLAGS += -MP
override CFLAGS += -Wall
override CFLAGS += -Wconversion
override CFLAGS += -Werror
override CFLAGS += -Wextra
override CFLAGS += -Wold-style-cast
override CFLAGS += -Wsign-conversion
override CFLAGS += -Wuseless-cast
override CFLAGS += -fdata-sections
override CFLAGS += -ffunction-sections
override CFLAGS += -g3

override CFLAGS.release += -DNDEBUG
override CFLAGS.release += -O3
override CFLAGS.release += -flto

override CFLAGS.debug += -O0

SRC := ${wildcard *.c}

build/release/a.out: override CFLAGS += ${CFLAGS.release}
build/release/a.out: ${patsubst %.c,.make.cache/release/%.o,${SRC}} | build/release
${LINK.c} $^ -o $@

build/release:
mkdir -p $@

.make.cache/release/%.o: %.c Makefile | .make.cache/release
${COMPILE.c} $< -o $@

.make.cache/release:
mkdir -p $@

build/debug/a.out: override CFLAGS += ${CFLAGS.debug}
build/debug/a.out: ${patsubst %.c,.make.cache/debug/%.o,${SRC}} | build/debug
${LINK.c} $^ -o $@

build/debug:
mkdir -p $@

.make.cache/debug/%.o: %.c Makefile | .make.cache/debug
${COMPILE.c} $< -o $@

.make.cache/debug:
mkdir -p $@

-include ${patsubst %.c,.make.cache/release/%.d,${SRC}}
-include ${patsubst %.c,.make.cache/debug/%.d,${SRC}}
>>
>>107516624
That crap is AI generated.

I'm all for AI-generated code in dossiers and whatnot, but never use AI-generated code in production.

What the fuck is `build/debug/a.out`. That is the most retarded Makefile rule I've seen. I think it's trying to imitate Cargo?

Just don't use AI-generated code for any reason, except learning.

Anon can, for example, feed dozens of books on Make and ask it to generate a 22-chapter book that teaches him how to write Makefiles. Then, he can always write his own.
>>
>>107516678
Maybe go ask "AI" to explain it to you, schizo, because I wrote it myself, I know that you're mentally ill here and still use C, so I just ran my C++ Makefile through sed to convert it for C projects, and removed the more useful features like profiling and testing because fizzbuzzers need neither here.
>>
>>107516578
Now just add a feature to only recompile compilation units that have source files that have been touched since the last build, and you've started on the road to reimplementing Make.
>>
>>107516578
make has been written by an autist so obviously its all retarded
i used to bother with various shit like compiling and pulling in libs from elsewhere on my computer and whatnot
but its intellectual onanism
hers a working makefile, half generated with a shatbot bc i cant be arsed to go through the documentation again
# Compiler and flags
CC := gcc
INCLUDES_PATHS := $(shell find . -name '*.h')
INCLUDES := $(foreach path, $(sort $(dir $(shell find $(CURRENT_PATH) -name *.h))), -I $(path))
CFLAGS := -O3 -march=native -mbmi -flto -fgnu89-inline $(INCLUDES)
PROGRAM_NAME := arduino-server


# Directories
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := .

# Target
TARGET := $(BIN_DIR)/$(PROGRAM_NAME)

# Find all source files recursively
SRC_FILES := $(shell find $(SRC_DIR) -type f -name '*.c')

# Convert src/path/file.c obj/path/file.o
OBJ_FILES := $(SRC_FILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)

# Default target
all: $(TARGET)

# Link object files into the final binary
$(TARGET): $(OBJ_FILES) | $(BIN_DIR)
$(CC) $(CFLAGS) $(OBJ_FILES) -o $@

# Compile each .c into a mirrored .o path under obj/
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@

# Ensure output directories exist
$(BIN_DIR):
mkdir -p $@

# Cleanup
clean:
rm -rf $(OBJ_DIR) $(PROGRAM_NAME)


re: clean all

init:
@echo "creating folders"
mkdir obj
mkdir src
mkdir inc

.PHONY: all clean


you put it into the root of your project then run "make init", its gonna generate 3 folders:
inc/, obj/ and src/.
inc is there to put your headers in
src is for your source, including main
obj is where the .o files are stored
your binary appears at the root of your project
you define the name thats gonna be given to your binary by changing the PROGRAM_NAME variable, here its arduino-server
>>
>>107516789
>putting package management slop into Makefile
oh no no no
>>
>>107516816
thats what it exists for, sharty fucking retard
>>
>>107516696
If your hand-written code looks like AI, that's cause for concern.

I can buy you a 9yo Afghan bride to soothe your pain of being a bad programmer, if you are willing to convert to Islam.

For reference, this is a good programmer:

https://www.youtube.com/watch?v=95M6V3mZgrI
>>
>>107516520
Pray tell, what is the difference between compsci and SWE?
I dropped out of college after my CS 201 course so I don't even know what CS is in america. But it seems largely the same thing. Does SWE just not teach big O notation or something? Seems dangerous, but I've seen college grads accidentally introduce O(n^3) code before when O(n) would suffice. But I would assume people knowing big O would have an easier time debugging
Or does SWE just not teach stuff like node traversal through graphs?
>>
>>107516829
I'm not concerned with opinions of someone whose posts look like they belong on reddit.
>>107516828
Make exists for building software, if I wanted to let users to install it, I'd write install.sh that calls make for them since users who try to compile without a package manager are mouthbreathers most of the time.
>>
>>107516873
>Make exists for building software, if I wanted to let users to install it, I'd write install.sh...
you dont make sense
i think youre just retarded
>>
>>107516890
Show me what you wrote that deserves a
make install
.
>>
File: tech_priests_of_mars.jpg (251 KB, 1080x762)
251 KB
251 KB JPG
>>107516520
>hey teach you the science of computation, not how to write web programs!
Which is probably better in the long run. What with AI making software engineering obsolete, but we will still need people to understand the fundamentals of the technology we're building society on.
>>
>>107516832
It depends on the country. In most countries not located between Canada and Mexico, SWE is more about 'engineering' software and compsci is about science of computation. CS is *entirely* theoretical, and has few actual practical courses.

In the US, it used to be like that. But then, for some reason it seems, people kept applying for CS when what they really needed was SWE. So universities there started shifting their carricula towards that instead.

Now, mind you, the US is the Babylon Whore of the countries, and people know a lot more about the US than any randow country out there. So there might be other countries that SWE and CS are mixed up.

Also, most countries have a centralized carriculum, whereas in the US, they're full Ayn Rand, and every college sets its own lesson plans. This means, whereas one college teaches the 'right' SWE/CS, another college might teach another.

If there's underageb& from the US in this thread, do make sure you don't fall into this trap. Make sure you know the difference between SWE and CS before you apply to college. I've met several people on Discord who did not know, and they're now in regret.
>>
>>107516896
Yes, the point here is, some universities across the world did not get the memo, and when they teach CS, they teach SWE instead.
>>
>>107516974
I wouldn't know. I enrolled in an SWE program and I got what I signed up for.
>>
>>107516894
>strawman
i could shove my cock in your mothers orifices instead
shes gonna like it
especially after ive dilated some of them enought to accomodate me
>>
>>107517023
cope loser, installation doesn't belong in a makefile
>>
>>107517038
>catastrophic reading comprehension failure
you should be posting on /lit/
>>
Why does the scanf man page show that scanf only requires a format string as an argument? I was trying to call scanf from a toy assembly program and it threw me off.
Also, where can I go to find out what registers are corrupted by libc calls? Scanf apparently corrupts rcx, but I didn't see any reference to that on the man page either.
>>
>>107517128
>Also, where can I go to find out what registers are corrupted by libc calls?
System V ABI
>>
File: scanf.png (19 KB, 456x168)
19 KB
19 KB PNG
>>107517128
don't know what man page you're looking at, that's clearly a varaidic function my guy
the ... means anything while the format string is basically your actual function signature and what actually specifies what types the function is going to try to access

>Also, where can I go to find out what registers are corrupted by libc calls? Scanf apparently corrupts rcx, but I didn't see any reference to that on the man page either.
Sys-V ABI for C, the Itanium ABI (not the hardware) which is built on that for C++
>>
>>107516959
>>107516974
Also, there are *few* uses for a fully theory-based CS program out there. One use is program verification. I'm actually trying to get my CS degree so I can do program verification. This is not automated reasoning, you actually sit down with a pen an paper (or LaTeX) and verify the program with logic.

Problem is, few programs out there could be verified with logic. I/O-heavy programs are not worth it at all.

CompCert is a compiler by INRIA that is verified by automated reasoning (Coq, or whatever it's called now). So even compilers now use automated reasoning.

Still, with automated reasoning, it's best to have someone trained in theoretical CS at helm. But seeing that, nobody uses CompCert, I don't know what the use would be.

People praise Rust, and bash Static Analysis. Not realizing, it's Rust static analysis engine that attracts programmers.

>>107516993
The two times I enrolled in an SWE program (studied 3 semesters, and 2 semesters, respectively, because the credits weren't transferable) I did it because cheap, crappy colleges here only offer SWE. I always wanted CS, ever since I was 12. I got accepted into IAU's ECE program, but I chose to study English lit, because it was at a *good* college. Dropped out after 3 semesters. I don't regret wasting my time for fourteen years. If I get accepted into FUM's CS program this year, it'd all be worth it. My three semesters of English lit was far more useful than 5 semesters of SWE, because I used my knowledge of English to bootstrap my knowledge of CS/SWE both. You guys don't know how bad people who don't know English have it in the self-education front. Resources are very rare in other languages.

Honestly, if you don't speak English in this field, you are fucked. In my stint at college, I met people who did not speak a lick of English. They did not, for example, know what "status" meant. So even the basic code the teach wrote on the whiteboard, they just blindly copied it.
>>
>>107517230
>the ... means anything while the format string is basically your actual function signature and what actually specifies what types the function is going to try to access
How would I know that I need to pass the address of a variable from reading the man page then? Is there a man page that says how to read the manual, too?
>>107517190
>System V ABI
Thanks, I'll check this out.
>>
>>107517419
kinda?
the POSIX version of the manpage for scanf is a stub that says to check the manpage for fscanf for the actual manpage and that's where an actual usage guide is
it seems like maybe it's just the GNU version that's particularly shitty
>>
>>107516595
>Makefiles
>Portable
Nice bait, chud.
>>
>>107517582
>POOSIX docs are shit
use Linux docs, simple as
Also why would you want to ever use scanf? Just parse data yourself.
>>
https://www.youtube.com/watch?v=nKr83nueCFE

lol Europoids were fucking losers, that's why they had to invent the printing press. Here, we had the "Mirza Benvis", scribes who worked in tandem to churn out codex after codex to those who paid. Everyone had several copies of the canons on their shelf, copied by the "Mirza Benvis". No monastery was needed. Price of getting a manuscript copied, with miniature paintings, was price of a week's meal.

Printing press is tech, shut up.
>>
As a college student how do I look at an example and not copy the code without getting caught for plagiarism? I looked at an example on YouTube on how to do something and I tried changing the variables and order of the lines and somehow I still got caught. They tracked the exact video where I go the code from. How is that possible? When I rewrite something in English that I find on the internet explaining a concept I don't ever have this issue but with programming I don't understand how it's considered plagiarism and get caught for it. How do I rewrite code without it coming back as plagiarized?
>>
>>107518420
Wait, they don't have you write code on paper?

Our teachers had us write code on paper, because they did not wanna bother check for plagiarism, and their thinking was "As long as you write the code on paper, at least you've interacted with it".

I like this approach much better.
>>
>>107518420
If you copy concepts you shouldn't know and you even copy the mistakes, and you use the exact same number of redundant variables and pointless checks, and you copy the first promoted goytube video that appears, it stands out.
>>
>>107509701
what does pace represent? why are you -90.463542 pace on jumps
>>
>>107518420
Watch explanations, understand concepts, close video, implement your solutions from your mind based on your understanding.
And cite your sources. Academia loves that.

That last part goes for professional work too. If you nab some code snippet from stackoverflow or get your ai to generate it for you, put a comment with the link to where the code came from or an explanation so that following readers can follow the thinking that went into the piece of code. It's about transparency and accountability.
>>
>>107518543
>"As long as you write the code on paper, at least you've interacted with it".
Like, by hand? Because you hardly even need to look at code to print it.
>>
>>107518690
Yes, by hand. I have a horrible handwriting, so I dictated it to my mom and she wrote it for me. Try to explain "curly braces" to someone who's never touched a computing device besides a smartphone, lol.

Thank God I dropped out, because my mom was getting sick. She thought she's doing my homework, for some reason.
>>
>>107518720
*she was getting sick of it.

Two words change the semantics considerably.
>>
>>107518720
That's terrible. That's worse than when I was in school 15 years ago and they had us print all the code handed in for assignments because the professors thought it was easier to read and grade like that.
>>
>>107518720
>>107518753
My guess is exams will make a comeback because it's so easy to cheat on coursework with AI now. The best way to test programming ability is probably thus: students are examined on school laptops that have a compiler but aren't connected to the internet.
>>
>>107518753
I think it was only the teachers at early semesters. Remember I dropped out after 2. Of course I'm still registered there, and I plan on going back the next semester... If I have the money. I dunno, I haven't decided yet.

We had one programming course in first semester, one programming course in 2nd. The rest of the classes were math and shit, which were the ones I cared about.

Both professors for programming classes were female. Women don't make for good programmers, but they make for WORST teachers.

The 2nd semester started out with C++, and ended with Java. I realized, man, I know how the JVM works, I've at least tried implementing it several times. Our teacher did not know much about garbage collection, even. I tried to ask her about it, and she thought I'm trying to show off. Whenever I did something extra with the code, she told me "You're showing off!". What a cunt.

The only reason I wanna go back is, I need a damn degree. Otherwise, my boss who hired me for my current program safety job told me, and honest to God, this is someone with a master's (or PhD, not sure) in SWE, that "You know more about PLT and compilers than the average university professor".

Still, even he kinda abuses me because I don't have a degree :(
>>
>>107518821
Our crappy college had a lab with 12 computers. I had to leave the lab --- and my teacher agreed after I showed her my 70-project Github, because I realized I have to share a computer with five 18yo girls. I fucking hate 18yo girls.

Worse: their compiler was MSCV, and as someone who is a martyr of free software, I won't, EVER, use a Microshaft product. I don't know why these morons had MSVC installed, a cracked version probably, because I don't think they had the money to license it lol.

Some 'meme' colleges across the world, like mine, are in similar situation. Also, this is a situation specific to my country, but laptops are expensive. The reason our teacher had us write code on paper, was partially, not to force students to own a laptop or a desktop PC. Sanctions have been extremely harsh on electronics prices.

The same laptop that cost 800k tomans now costs 75 million tomans. I'm not kidding. I don't doubt there are families who postpone buying laptops for their SWE student children.

I hope Jews get nuked to pieces for tanking our currency. Jews are subhuman scum that don't deserve to exist in the same plane of reality as humans.
>>
> not watching Lord Matt Godbolt's AoCO series daily

https://www.youtube.com/watch?v=Hu0vu1tpZnc


My biggest fear in life is Matt being Jewish because he's got a very Jewish last name. But he does not 'look' like a Jew, does he.

Matt is royalty in compiler engineering. There's no other tool that does what his Compiler Explorer does. And yet, he wanted to add my shitty preprocessor (https://github.com/Chubek/Ekipp) to CE. I told him it has no sort of IR.

I love Matt, even if he's Jewish. Matt, if you're reading this for some reason, I wish you the best of luck, and I hope you can finish all 25 episodes of AoCO.
>>
>>107518543
Are you from India? Who tf writes code on paper??
>>
>>107519063
Iran, which is honestly closer to India than it is to Europe, but you're wrong about Indians writing code on paper. Indian colleges want to force their students to buy laptops, even if they are poor. So their colleges are extremely laptop-based.

Here, most colleges have large labs, so they don't force their students to buy laptops. My college 'specifically' had a small lab, it was a meme college.

You morons think writing code on paper is Jeet-ish, but keep in mind that, it's the Jeets whose SWE courses are extremely computer-based, and they don't offer the best programmers to the world, do they.

If the student writes code on paper, they will have a better understanding of it. In other countries, laptop manufacturers team up with colleges to force-fuck students into buying latops. Here, we are sanctioned by all manufacturers, so we don't have to necessarily do that. This gives the teachers freedom to force their students to write code on paper, which is the superior way.

Especially, if they write code on paper, it make them understand the code, even if they copy it from AI or some place else.

Overall, it will be similar to math homework they did in high school, rather than viewing 'code' as something a computer deals with strictly.
>>
File: angry-karen.png (555 KB, 1024x1024)
555 KB
555 KB PNG
Can somebody tell me why I cannot add someone's number to my Telegram contact list, and they can't add my number too?

It says the number is not registered on Telegram or some shit like that.

Why do Russians suck so much at writing chat programs? Have they realized that Westoids consider Telegram the hub of scum and villainy, and just gave up?
>>
>>107494927
HOLY SHIT IT'S UP https://www.youtube.com/watch?v=6wQ7pl7DVHw
>>
>>107519179
>if they write code on paper, it make them understand the code
lol
>>
Do you guys have some kind of pastebin of resources to learn how to code?
Otherwise, where does someone even start?
>>
>>107519590
Both approaches suck. You should not even have an introductory student code:

https://par.nsf.gov/servlets/purl/10159390

You should teach them theory of coding, without writing a single line of code, whether on a computer, or chiseled on a stone.
>>
>>107519590
Also, consider this. We had what I can only describe as a 'char woman', and her daughter got accepted into FUM's SWE program. This was before the sanctions, but even then, her family, with an out-of-work dad and a char woman of a mom, could not buy her a computer.

In the US, when a student goes to college, they are automatically assumed to be able to purchase a computer, because if they can afford 200K USD college tuition, they can afford a fucking laptop.

But in countries with free college, you cannot favor this assumption. You could either give them free laptops (which they do, in later semesters, if they cannot afford it) or you can have them write code on paper for early semesters, and take them to a lab to interact with a computer.

Remember, a "PC", that is, a computer descended from the IBM PC, is not the only form of computer. You are a moron if you think an IBM PC is the end-all be-all to computing. Having students buy an IBM-compatible PC is stupid. Sure, they've taken over the world --- but it's best to have a curriculum that favors to architecture.

I don't expect a selft-taught person like you to understand this, anon. You're probably a webdev who uses an IDE he pays $300 a year for. No offense.
>>
>>107519611
read nigga
>>
>>107519848
read what exactly, the OP is empty
>>
>>107519705
>You could either give them free laptops
What, do computer labs not exist anymore?
>or you can have them write code on paper for early semesters, and take them to a lab to interact with a computer.
Oh, so they do exist. Then there's no need to make people code on paper.
>>
>>107519880
books
>>
>>107520179
Care to name one or just want to carry on with the smug faggot act?
>>
>>107503706
at least do Clojure/Janet/Hy syntax
>>
File: thegoodparts.jpg (584 KB, 3264x1836)
584 KB
584 KB JPG
>>107520235
K&R
Or the Rust book https://doc.rust-lang.org/book/
Or any damn book you can get your fingers on for whichever language interests you.

The Rust book is not bad to begin with, come to think. It's pretty hand-holdy and you don't even have to get a physical copy of you don't want to.
>>
>>107520361
thanks
>>
File: 1764140312901160.jpg (505 KB, 1536x2048)
505 KB
505 KB JPG
>solve 200 leetcode problems
>learn that I want to avoid dictionaries whenever possible in favor of arrays, because arrays are 5-10x faster while using 50-75% of the memory
Yeah I can't imagine that skill will translate well when I get a job
>>
>>107520726
>>learn that I want to avoid dictionaries whenever possible in favor of arrays, because arrays are 5-10x faster while using 50-75% of the memory
Good experience.
>Yeah I can't imagine that skill will translate well when I get a job
Not sure what you mean. The next thing to learn is to know when you need you code to be performant and when it doesn't matter so much in favour of simplified readable code. And also to learn to cooperate with people.
>>
>>107518576
How do I know which are the concepts in a big project and how do I write those concepts in my own words?
>>
>>107520777
Are you sure you're ready to be a collage student?
>>
>>107520777
What I meant was that if you are doing a starting exercise involving arrays and you bring out a hash map because a video told you that it was more efficient, the professor will be suspicious and ask you what the fuck you think a hash map is or fail you.
It doesn't surprise me you're too dumb to copy things because you can't even grasp the minimal underlying concepts, I have seen people literally copypaste Wikipedia and keep the [1] citations [2] on the text.
>>
everything i write is broken and people make fun of it.
>>
>>107518420
>>107520777
Tips for university: Fucking go to class, and when you go to class, actually fucking pay attention. That's like 95% of the way to your degree.
Unless the course is absolutely awful, they will have taught you what need to know in order to complete the assignments.

Referencing other code is something you absolutely do a bunch of in the real world, but doing so without understanding it is how you generate absolute crap.
>>
>>107520726
With so many data structures and algorithms, the "good" ones often don't actually become good until what you're dealing with is relatively large. At small n, often the basic shit wins out.

Insertion sort, my beloved.
>>
>>107521049
Post code for us to make fun of.
>>
Good day.

I am God, the Almighty, and Whose hands are judgement, and mercy;
And I will cause My judgement, to fall upon the willful violators of My commands;
In My own time, according to wisdom, and truth;
In this world, or eternity;
For I have created all souls, and for me they are accountable;
Fear Ye, the LORD.
>>
>>107521601
//non blocking sleep
void main(void){
fork();
while(true)
;
}
>>
there are 4 subdisciplines to software development:
1. language mastery (learning all the features of a language)
2. computer science theory (automata theory, graph theory, etc.)
3. software engineering (boils down to identifying & familiarizing yourself with different architectures)
4. tech domain knowledge (how anything works, from network protocols, to AI, to crypto, to operating systems)
do you agree or no? why isn't software development more well defined as a field?
>>
>>107521986
UB
>>
>>107521601
Here's a code for people to make fun of:

typedef struct AbstractSyntaxTree
{
int type;
struct AbstractSyntaxTree children[2];
} AST;


This is a retarded thing that I've done, and we've all done at one time or the other.
>>
>>107521986
Fuck you
>>
>>107522016
What's so bad about this? Why did you do this?
>>
>>107522071
Nothing. He's a "don't try hard".
>>
>>107522071
>>107522107
the only thing i can see is children are not pointers but other than that there is nothing wrong
>>
>>107522071
>>107522107
>>107522117


For an AST, you'd probably wanna do Algebraic Data Types. Yes, you can do them in C, since C is compliant with System-F.

struct AST
{
enum
{
AST_Constant,
AST_BinaryExpression,
// ...rest
} kind;

union
{
Constant v_constant;
BinaryExpression v_binop;
// ... rest
};

struct AST **children;
size_t num_children;
};


This style of "anonymous unions" (which could be a struct, too) is illegal in ISO C, but works in GNU C (both Clang and GCC).

Also, using a Binary Tree for your AST is retarded. You must do a plain, unbalanced tree, if you wanna go full sloppy:

struct AST
{
int type;
void *data;
struct AST **children;
size_t num_children;
};
>>
>>107522131
You can do name the union something like `as` if you want it to be ISO-conformant. My ASDL implementation does that (AFAIK, not sure, I wrote it two years ago). https://github.com/Chubek/ZephyrASDL.
>>
I have recently slopped out a dossier on implementation of ECMAScript (I call it that, because I fucking despise the kike-lover who owns the right to "JavaScript", and if you guys wish to not allow Zionist goons to get scott-free off of their war crimes, you'd call it that, as well!) and this dossier is just too fucking good so here it is:

https://chubak.neocities.org/docilejs-dossier

It's called "DocileJS" because it's not "mobile".

>>107522257
I text her. And it's the inverse situation, I've texted her about 45 times, and she's responded 7-8 times. I text her with my top-notch Norm MacDonald-style of humor, and she responds with one-two lines.

I'm not worried. I'll get her, eventually. When I used to text girls in my youth (I'm 32), there were no emojis. Now that we got emojis, the whole "texting game" has changed. Thank God for the Unicode Consortium, and the gooks who invented emojis (although, Y! Messenger had "Smilies" before that).
>>
>>107522131
>For an AST, you'd probably wanna do Algebraic Data Types. Yes, you can do them in C,
no fucking shit, you don't say
>>
>>107509963
That's not a free variable. A free variable is a variable not bound in a scope.
(let ((x 3))
(let ((y 5))
(+ x y)))

x is a free variable in the inner let, because it's not bound in that scope.
>>
>>107522792
and what is y bound to in my example?
>>
So, I just discovered that MacOS's `mmap(2)` has a MAP_JIT flag!

Seriously, why does Linux not have this option?

This OS is truly premium. I just realized why an Apple computer costs thousands. And I'll never get a whiff of this OS.

I mean, if I work hard, I can probably afford a machine from 2022-2023. But here's the problem, my program safety job does not pay me enough to buy an Apple machine -- at least not yet. Even if I am officially hired by them to churn out static analyzers and compilers, it'd be at least 2 years until I can buy an M4 machine.

I could roll up my sleeves and add this option to Loonix, though. But I don't even know what does this flag do? Can someone lemme know? Thanks.

inb4 anti-Apple poorfolk will come after me. Face it, homosexual african-americans, Apple hardware and software is premium.
>>
>>107524086
i fucking hate virtual memory
why cant all memory just be real

just because some dumbfucks cant stay within their bounds i have to suffer
>>
>>107524086
you're assuming MAP_JIT is premium when you don't even know what it does? you wouldn't be skilled enough to add it to linux. macos hardened runtime requires code pages to be signed. MAP_JIT can be used with mmap to allow bypassing the hardened runtime, assuming the process calling mmap has the "allow JIT" entitlement
>>
>>107524130
You hate "virtual memory"? Are you accessing 4chan from an IBM 360 machine? Because almost any machine that came out after that, since mid-1960s, has had an MMU and supported virtual memory.

`mmap(2)`, want it or not, is how most Unix-like operating system allocate memory now. There's no other way -- you could use `sbrk(3)` or if you wanna go lower, `brk(2)`. But most `malloc` libraries use `mmap(2)` now. Google's CTMap (I think that's what it's called? It starts with CT*) adds even more abstractions. So does RPMalloc and all the other "non-standard" mallocs.

If you don't want "virtual memory", get a microcontroller, because all microprocessors have an MMU and do virtual memory.

I think you mean "disk-cached memory" -- what people used to call a "slave memory" back in the day, which is again, wrong. `mmap(2)` does a lot of things. Disk-cached memory is just one of them. If you pass MAP_ANONYMOUS to it, it will allocate memory on the volatile memory device (some require passing `fd` as -1).

I don't mean to be mean btw. Just tryna educate.
>>
>>107524163
I always wanted to tinker with the kernel. It could be a starting point. Can you explain what "hardened runtime" is, anon? It's a hard phrase to search for. So you're saying MAP_JIT bypasses an extra step Apple has added for memory verification? If so, fuck that. I change my mind.

What I thought it does is, it would ease up the deopt and stuff like that. I imagined it would, for example, help with On-Stack Replacement.

But if all it does is bypass Apple's needless addictions, then fuck that. Apple sucks and so does Microshaaft.
>>
File: angry-emoji-straw-hat.png (462 KB, 1024x1024)
462 KB
462 KB PNG
>>107524200
Forgot my angry emoji.
>>
>>107524200
btw, I realize I'm a bit low on OSDev knowledge, I'm waiting to make my own compiler, then get into OSDev. Probably in the next year or so. I have about ~60 books on OSDev I could feed to Sonnet 4.5 (hopefully, Sonnet 5 by then) to make a dossier with.
>>
whats the current meta for gui frameworks in crablang
>>
>>107524389
I remember I wanted to write a terminal emulator with egui, and it seemed promising. But folks say iced is better apparently.
>>
>>107524408
>egui
i am not a fan of immediate mode
>iced
I used to use Elm and found the developers to be massive faggots operating purely on a circlejerk, hopefully this is better

I'm also going to test out Slint since I'm a big fan of declarative syntax
>>
Currently writing a gameboy emulator in C++. I implemented till opcode 0x8F, and also implemented MBC0-3. I went with a function pointer array design for opcode. I hope to complete this in the next 6 months, along with colour support hopefully
>>
>setjmp
>Saves the current execution context into a variable env of type jmp_buf.
What's an execution context, exactly?
>>
>>107525486
registers
>>
File: file.png (64 KB, 1467x1067)
64 KB
64 KB PNG
>vibe coded a plot rendered using WebGPU in rust
oh this is definitely not how any of this shit is supposed to be done but damn it's kind of fun
ran out of tokens for today

I hated trying to learn GPU shit there's so much boilerplate
>>
>>107525486
>>107525495
https://git.musl-libc.org/cgit/musl/tree/src/setjmp/x86_64/setjmp.s
>>
>>107525486
`setjmp` does not rewind the stack. So it does not really 'save & restore the current execution context'. Use it with care. Non-local jumps are retarded. Some compilers are smart enough to take it into account when building the CFG. But most don't, since it is entirely mercurial.

When you build the CFG, you gotta identify the 'leaders'. Anything after 'return from function' in your IR (e.g. GIMPLE, LLVM) is a leader. Everything after a label, too, is a leader.

But how exactly do we identify a leader when it entirely depends on the runtime? As the other anon posted, GCC implements it entirely in assembly. No IR here is presented. The CFG does not take non-local jumps into account at all. Because it can't.

This is the problem with both local, and non-local jumps. Local jumps turn your perfectly fine "Natural Loops" into a soup of back edges. Non-local jumps just take that to 1000lvl, and fuck this shit up.

Use non-local jumps ONLY if you need them.
>>
>>107525635
>>107525713
I'm too dumb for this.
>>
Why do I always see the suggestion to generate PI = 4*atan(1) and not PI = 2*acos(0)?
>>
>>107525486
setjmp contains the instruction pointer (that, when you go to it, it goes to the place where setjmp would return in the caller's function) and the callee saved registers which includes rsp and rbp. Doing a longjmp is exactly like if setjmp returned a 2nd time.
>>107525713
>`setjmp` does not rewind the stack.
But it does? Unless you choose a definition of "rewind" that makes you right. Of course it doesn't rewind in the sense of continuations or backtracking.
>Non-local jumps are retarded.
filtered
>The CFG does not take non-local jumps into account at all. Because it can't.
It doesn't need to. The compiler doesn't have to do any kind of special register handling beyond function calls. The only thing setjmp/longjmp requires to work is that the function calling convention is respected, which it is.

.t implemented setjmp and longjmp for linux x86_64
>>
>>107526228
>setjmp contains the instruction pointer and ...
I mean jmp_buf.
>>107525713
also I think you are getting mixed up about the CFG, that what you're saying would be relevant but for computed gotos
>>
>>107526228
>Doing a longjmp is exactly like if setjmp returned a 2nd time.
Thanks, this is the only part that I maybe understood.
>>
>>107526547
It's simple really. Longjmp does 3 things:
- it resets the current stack frame to the one where setjmp was called
- it resets a few general purpose registers so that the function can continue where it was left off in terms of statements and expressions
- it jumps back to the right place in the function definition where setjmp was called

Even long jumping back into the middle of an expression works. That's how well the registers are restored.
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

int b;

int get_b(jmp_buf buf) {
longjmp(buf, b);
return 0;
}

int func(int a) {
jmp_buf buf;
int b;
return a + ((b = setjmp(buf)) ? b : get_b(buf)) * 2;
}

int main(int argc, char **argv) {
if (argc < 3) {
return 1;
}

int a = atoi(argv[1]);
b = atoi(argv[2]);

printf("%d + %d*2 = %d\n", a, b, func(a));
return 0;
}

$ make && ./main 2 5
2 + 5*2 = 12
>>
File: tet5.png (791 KB, 1640x865)
791 KB
791 KB PNG
I wish KWrite's Forth parser was a little less stupid. It only seems to color things correctly if they're on the first column. You can see on:

- line 7: the 4 isn't blue,
- if I insert a newline to put "value #10" on the next line the "#10" turns red instead of the purple I'd expect,
- the "\ arith" comment isn't gray, and on
- line 8: the ">10+>" name isn't purple.

I use it anyway. First thing I tried and it's mostly fine, it has some useful features with little fuss.
>>
>>107527315
>soviet stacker
what?
>>
>>107527486
The Tetris Company are touchy with their trademark. Better to nip that in the bud, plus the Forth "stacker" pun is delightful.
>>
>>107527143
get_b() never returns, right?
>>
>>107527504
>*starts playing*
https://www.youtube.com/watch?v=yyT7Q5tGIwI
>>
>>107527538
nope. I made it a function that returns an int to please the type checker.
setjmp(buf) is called a first time and returns 0
get_b(bug) gets called
longjmp(buf, b) is called
setjmp(buf) returns a 2nd time with the value of b, if b != 0. If b == 0, setjmp(buf) will return 1.
>>
>>107527997
>setjmp(buf) will return 1
You mean 5? With the input in your example. Since you set the global b = 5 and pass that as argument to longjmp.
>>
>>107528050
>You mean 5?
Yes. But if b is 0, setjmp will return 1 instead. That's a spec requirement, the intent is to avoid accidental loops.
>man setjmp.3
>If the programmer mistakenly passes the value 0 in val, the "fake" return will instead return 1.
$ ./main 2 5
2 + 5*2 = 12
$ ./main 2 0
2 + 0*2 = 4
>>
>>107528078
>But if b is 0, setjmp will return 1 instead.
b will be assigned 0 because setjmp() returns 0. Which causes the branch to call get_b() which makes the code do a Sands of Time style "let me try that again" rewind to an alternate universe where setjmp() returns 5. That's how I understand it after some headscratching.
>>
>>107528164
No I mean if the global variable b = atoi(argv[2]) == 0, longjmp will be called with the arguments longjmp(buf, 0), then setjmp(buf) will return 1 and the local variable b inside func() will then be assigned to 1. There is a conditional inside setjmp. (conceptually, there is an assembly trick to avoid it and accomplish the same thing).
>>
>>107528306
>longjmp() cannot cause 0 to be returned. If longjmp() is invoked with a second argument of 0, 1 will be returned instead.
Oh
>>
>>107528306 cont
also I just modified my implementation of longjmp(env, val) to always return val and it leads to an infinite loop when if val == 0
>>
>>107528352
>and it leads to an infinite loop when if val == 0
Yeah, I could see that.
>>
>>107528306
That would cause
$ ./main 2 0
2 + 0*2 = 4
>>
>>107521361
You don't learn every single concept in class, you briefly go through the basics but for the most part you have to figure out everything yourself. Fucking idiot.
>>
What's the difference between a software and a software component and what are some examples of software components?
>>
>>107529103
Nobody says "a software" just as nobody says "a hardware". That's just bad grammar.
Software is the abstract set of logical instructions stored on- and carried out by- programmable hardware.
Software components are software just as hardware components are hardware. And in both cases components are just pieces of a bigger whole.
>>
>>107529103
Software:
- is data stored in the memory of a computer that
- can be interpreted as instructions by the computer processor, so that it
- modifies other data in the memory and
- interacts electrically with external hardware, mainly I/O devices: keyboard, mice, screens, speakers.

A "software component" is a social construct. It's not a real thing. Just another in the long line of complexities invented by corporations to milk people out of their money.
>>
>>107529496
>keyboard, mice, screens, speakers.
servos, printers paper or plastic, barcode scanners, light detectors, cameras, microphones, on and on and on
>>
I wonder if C++ templates in practice end up as a performance loss, since they bloat up the instruction cache
>>
>>107529636
it depends but usually not and there are at least some big gains (e.g. sort with fused in comparator and size/alignmen vs unoptimised qsort)
>>
>>107418581
>>After the bits for one sample have been gathered from the bitstream, the first bit has to be inverted.
>I don't get it. Why don't they just send the bit in the state it should be?

I found the answer:
>The inversion of the most significant bit (MSB) is done in order to
avoid the all ‘1’ representation of the code, because the all ‘1’ code is used for the synchronization word.
>>
>>107529103
I hope that you pass your 100 level class because these are some horrendous questions you're being asked.
it's like asking what's the difference between automobiles and a car
you're wasting your money wherever you're going to school at
>>
>>107529800
>it's like asking what's the difference between automobiles and a car
Englishing is hard.
>>
File: file.png (179 KB, 1839x351)
179 KB
179 KB PNG
i cant even
>>
I LOOOOOOOOOOOOOOOVE DECOUPLING
SEPARATION OF CONCERNS
INDEPENDENT SYSTEMS INTERACTING THROUGH WELL-DEFINED INTERFACES



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.