[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 / qa] [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


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1727967376106971.jpg (52 KB, 540x540)
52 KB
52 KB JPG
What are you working on, /tech/?

Resources:
Most important thing you will ever read: >>102778631
C++ reference:
en.cppreference.com
Anal sex tips and tricks:
>>>/lgbt/42069
>>
>>102773986
Linking to my post in the previous thread.
>>
>>102778865
stop messing with classes and just declare functions and global structures, will make your life 20 times easier
>>
Imagine that you made a programming language and want to convince anons to use it.
What would you do?
If your name is Drew, please ignore my post.
>>
>>102779108
Your language should stand on its own. If it can't do that it's a waste of time and effort.
>>
>>102779108
"it's not java"
>>
C/C++-bros, what are the OPTIMAL standard versions of C and C++ respectively?
C99 and C++20?
>>
>>102779293
c++14 is benissimo
>>
>>102779293
C++latest
>>
>>102779293
pre standard for both
>>
>>102779313
>>102779332
>>102779348
the triality of man
>>
>>102778837
How can I sell go to my manager? No one in the team knows it, but we can learn. We are leaning for python's fastapi, but upper management are java cucks. I wan tto propose something new.

>very large api that talks to a bunch of services
>no frontend
>gotta go fast
>>
h a s k e l l
>>
It's risc-v assembly for me
>>
For me, it's https://www.cs.rit.edu/~ats/books/ooc.pdf
>>
>>102779750
>object oriented cock
cringe
>>
>be g++
>oh look its just 5 syscalls, one condition, some exit conditions and some function calls
>let me compile this into an infinite loop

the condition is
for (uint32_t i = 1; i < argc; ++i)

and it is unreachable on no cli arguments passed
i feel dispair
>>
>>102779672
So true
>>
File: 75f.png (82 KB, 600x596)
82 KB
82 KB PNG
>>102779798
>i feel dispair
>>
https://github.com/Hirrolot/awesome-c-preprocessor
https://github.com/hirrolot/interface99
Cursed
>>
>>102779565
just tell them that google uses it. Maybe throw in some propaganda about it being python but fast idk
>>
>>102779565
>it's designed for retards like me
>>
>>102779798
Works on my machine. That loop shouldn't execute @ no arguments passed in. Are you sure its the for loop and not anything else?
>>
Do you take notes? And if so what do you use?
>>
>>102780275
Yes, put a gun to my head and i have no idea what else might be going on
>>
so i realized that the functions in error.cpp that call _exit() were returning, ...

#define _NORET __attribute__((noreturn))
>noreturn function does return, '}'
(they were void functions)

#define _NORET int __attribute__((noreturn))
>int function not returning


??????????


HAHAHAHHAHAHAHAHAHHAHAHAHAHAHAHAHAHHAHAHA

PUAHAHAHAHHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHÀAAAAAAAA

AAAAAAAAAAAAAAAA-
>>
>>102780199
ok sir good morning
>>102780273
I rather die than program in java. I looked into clojure but I'm the only lisper in the team, and I am not familiar with the JVM or Java, and clojure has too many gotchas related to that. I am more of a scheme guy.
>>
I have no idea what a thread is
>>
>>102780605
haskell
>>
>>102780613
you're in one
>>
>>102780617
I code in haskell, another guy is a big haskell head. There is ZERO chance of putting haskell anywhere near corporate code.
>>
>>102780667
I code in VHDL, another guy a a big VHDL head. There is BIGBOI chance of putting VHDL anywhere near corporate code
>>
>>102780667
yet corporate bullshit is everywhere near haskell now
>>
>>102779293
Rust 2024 Edition
>>
>>102780862
Rust is DEI approved though
>>
>>102780862
>memelang
>>102780876
To some, that sounds like a plus actually (even though it's a MAJOR minus)
>>
File: Hopper-3 square.jpg (78 KB, 511x511)
78 KB
78 KB JPG
>>102779276
>>
>>102780876
Yeah, RISC is good
>>
>>102781054
Rust Is Shitty Code
>>
so how come precompiled headers aren't just the default?
>>
File: 2024-10-11_13:39:05.png (64 KB, 500x500)
64 KB
64 KB PNG
R8 my LearnOpenGL follow-along.
I didn't follow it to the letter obviously, and I sort of gave up on doing my own abstraction half way through, but I want to know if there are any glaring issues in it.
https://files.catbox.moe/do2ejd.cpp
>>
>>102781293
inline.
>>
>>102781348
surely an intelligent compiler could figure out a way to support both
>>
>>102781419
>intelligent compiler
Lol
Lmao
And that wouldn't even be a job for the compiler, but for the linker.
>>
>>102779293
C89/ANSI is pretty good.
C99 is a good alternative though.
>>
File: shadows.webm (687 KB, 1762x1208)
687 KB
687 KB WEBM
>>102778837
>What are you working on, /tech/?
I've added a shadow option to my toolkit's box model.
And made a demo program that first get the pointer's position, then updates the shadows offset to create a reactive shadow effect. Endgame here is getting an UI to react to the direction and intensity of light hitting a device that has a light sensor.
>>
>>102781437
>the linker is responsible for inlining functions
anon, I...
>>
>>102781477
What, do you think, does "precompiled" mean?
And now fuck off.
>>
>>102779293
C11 just for anonymous structs and unions within structs and unions.
>>
>>102781487
so how exactly would the linker be responsible for inlining functions in your hypothetical scenario?
>>
>>102781305
oops, just noticed I left math.h and the PI const in there.
Those were from something I did when learning about Uniforms where I set the RGB value to a value of sin(currentTime) where each color is offset by 2PI/3 to get a proper pulsing rainbow triangle.

I really should start doing version control.
>>
>>102779293
C89/ANSI is pretty good.
C99 is a good alternative though.
>>
>>102781511
That's the fucking point. Precompiled headers rob the compiler of the ability to inline shit because compilers operate on single translation units. If code within a TU calls other code within a TU the compiler just marks this as an external dependence and leave it for the linker to resolve. When the linker then sees the reference it can't do much in terms of inlining unless you have link-time optimizations enabled, and because the linker doesn't have the same code generating information the compiler had during its work (it's all binary now) its ability to inline is diminished.
>>
>>102781602
how can precompiled headers possibly work like that? If I mark a function in a header static inline, then it clearly won't be a symbol in any binary, it's only available from the header. If the compiler just marks it as an external dependency, then the linker won't be able to find it in the first place. Obvously the compiler doesn't need to actually inline that function, but it at least needs to generate code for it and put it in the object file.
>>
Gonna crosspost this, since you guys might know what's going on. >>102781693

The window class is in Windows/Classes.c, and the window created is in Windows/Main.c. The menu is stored in Resource//M_Main.c, and icon in Iconography.c.
>>
>-Wextra -Wsign-conversion -Wconversion
>line LINE: lala_ptr = (int64bit-someotherpointer);
>warning blabla: implicit conversion between long int and long ling unsigned int may blablabla

WOAH, pointer arithmetic in gcc degrades them to 32bit registers, fucking unreal.
In this specific instance it wont matter but say you oopsie daisy forget to cast your 32bit integer to 64 bits?
destruction
>>
>>102781785
>how can precompiled headers possibly work like that?
They don't; that's the fucking point.
Precompiled headers are great for stuff you don't want inlined for whatever reason. For everything else they're terrible, and making them default is retarded, which is what the OP was asking about: >>102781293
>>
Im currently working on a cycle accurate NES emulator. It's my first time writing anything this low level. So far I have finished all of the legal instructions and verified they work.
The instruction interpreter is pure spaghetti code though. I have a switch statement on the current instruction cycle then a nested switch on the instruction register.
I decided to use zig instead of the old trusty C since the casting rules force you to be very explicit with your arithmetic and I just think comptime is neat. Right now I'm building a debugger + disassembler before I start working on the PPU and MMC1.
I have until mid December to finish. Wish me luck.
>>
>>102781964
>spaghetti
>he doesn't know the first, second, or third thing about emulation, a.k.a. using the opcode as index into a function pointer array
https://www.reddit.com/r/EmuDev/comments/h01yvg/best_way_to_handle_opcodes_of_processor/
>>
>>102778837
>Anal sex tips and tricks
I hate rust threads.
>>
>>102781602
>Precompiled headers rob the compiler of the ability to inline shit
No, because you forgot to note what the headers are precompiled to. They're not compiled to object files; they become more like IR files that can be sucked in very efficiently and still generate inlineable entities.
The point of a precompiled header is that it has one, fixed interpretation (this is common!) so the compiler can just reuse that instead of having to keep on reinterpreting it, and that speeds things up a lot in a complex project with deep include chains.
>>
>>102781958
it does inline stuff tho. I just tested it because I smelled bullshit. The real answer to anons question is that by definition pre compiled headers need a separate build step. But if you build them then they will be used by default. They do have a bunch of actual caveats mostly around macros and compiler flags, but not inlining.
>>
>>102781992
I saw this approach when I saw OLC's series on NES emulation. I find this to be a great way of solving this issue when working on an instruction ticked emulator but I want it to be cycle ticked. Wouldn't this force me to switch on the current instruction cycle inside of each function implementing an instruction?
>>
>>102782115
Not if the work each cycle completes for a given instruction is in its own function. You're already separating them anyway, don't you?
>>
>>102782177
I see. Right now it is separated like that. There are some workloads shared by a majority of the instructions such as fetching the operand from PC + 1. Here's how I have that specific thing implemented:
switch (self.current_instruction_cycle) {
1 => {
switch (self.ir) {
instr.LDAabs, instr.LDAzpg // rest of opcodes...
=> {
self.data_latch = self.busRead(self.pc);
self.pc += 1;
}
}
}
}

When I refactor the instruction interpreter I think I'm going to do what you mention and just reuse common operations.
>>
Temporary variables, yea or nay?
>>
>>102781471
how are you doing corners? polygons or rasterization?
>>
File: say_thank_you_gcc.jpg (960 KB, 3096x907)
960 KB
960 KB JPG
>>102782498
nay

make everything thread-local
>>
note that this is causing a segfault because within that append input there is an mremap to my pointer which is going to fail due to the lseek returning 0 and my input stream pointer being MAX64BIT

i have no fucking idea how this miscompilation is even happening, i have tried casting and all
>>
File: 1726848760261406.webm (1.64 MB, 1920x1080)
1.64 MB
1.64 MB WEBM
also concludes for some reason that the check for input_file_fd should never happen
Yeah gcc you are smart keep going
>>
>>102782625
>_Z9memcpy_zsPhs_y
>clearly C++ name-mangled
I'm going to steal this example for why I don't just use C++ with C semantics.
>>
File: corners.webm (2.66 MB, 1176x628)
2.66 MB
2.66 MB WEBM
>>102782616
I'm using Cairo's drawing primitives (arcs and lines) to create a closed path that is then filled.
>>
>>102782888
okay hitler, so I guess it is rasterization.
do you build cairo surfaces on the fly or you reserve an atlast to draw too?
what's the performance for generating a table like excel?
>>
File: 1716855020977647.jpg (33 KB, 253x310)
33 KB
33 KB JPG
>gcc has undocumented builtins like __builtin_va_start
>>
>>102783299
On the fly. More specifically, I first draw on a pixmap that get applied to the window with the X11 Present extension.

As far as performance go, Its mid-tier, I get ~500fps with the program of the 1st webm, but I also redraw the whole window in this demo each frame. With a more standard theme and usage, only the widgets that are interacted with will be redrawn.
>>
>>102781958
>stuff in the pch doesn't get inlined
are you on crack anon?
>>
File: colorful-v-2-1.gif (557 KB, 320x320)
557 KB
557 KB GIF
>>102778837
my shitty game from 12 years ago
I'm procrastinating on finishing up controller support so I'm adding some random tweaks here and there
>>
>>102778914
How do i do this in python? Yes, i know that python is not a real programming language, but i'm paid to write it.
More specifically, what do i use for global structures? There are tuples, lists, dicts, classes, dataclasses, namedtuples, some of these also support type hints, but half the libraries we use don't have any type hints so it's all useless. I'm having analysis paralysis right now.
>>
ComPtr<IDXGISwapChain3> m_swapChain;
ComPtr<IDXGISwapChain1> swapChain;
<...some stuff...>
swapChain.As(&m_swapChain)

I don't get this at all, you're getting a com pointer to a IDXGISwapChain1 but then you're making a com pointer to an IDXGISwapChain3 point to the same com object? is the interface just superficial and there's just one underlying type of swap chain object that supports all the interfaces?
>>
>>102783898
PRETTY, LOVE IT
>>
for (auto& i : std::views::reverse(container))

or
for (auto& i : std::ranges::reverse_view(container))


?
>>
>>102786894
yes
>>
>>102786894
for (auto& i : boost::ranges::reverse_view(container))
>>
>>102787238
>>102786894
i wonder how the fuck this slop doesnt miscompile for you
>>
>>102786894
for i in container.iter().rev()
>>
>>102787303
What slop? It's pretty much from the cppreference but the explanation is obscure
>>
>>102783855
looks neat anon.
>>
How do I get rid of this fucking impulse to launch a game, watch Youtube, do anything else than code when I'm on my computer ffs, this shit is killing me
>>
>>102790476
You don't
It's permanent until you reincarnate
>>
>>102790476
It's very simple: there's something you really, really, REALLY do not want to do, and so you're doing literally anything else but to push through the initial block after which it will get easier.

Just remember that. Push through once, get it behind you, and once you're going you're going.
>>
>>102790626
this has the opposite effect, the more times you do it the less motivation you have past the initial bit
>>
>>102791345
Wrong. I've just started with my own sprintf implementation, and it gets easier the further I'm into it.
>>
As a long-time C programmer, I strongly endorse the usage of Rust
programming language for its security features and performance gains. In
fact, both NSA and Microsoft are now moving to Rust, as they understand
that it's a game-changer in the industry. And don't forget about cniles,
who need to embrace change or risk being left behind.
Rust is taking over, so let's join the revolution and start writing better
code today!
>>
File: primer_malloc_3.png (701 KB, 1920x9950)
701 KB
701 KB PNG
>>102791463
Rust had it chance to get rid of individual lifetimes and they didn't do it. To top it off C compilers, with their decades of tried-and-tested code generation, still has issues with some optimizations, and I see absolutely no reason why Rust should be so much better at it.

Rust is dust.
>>
File: me.jpg (21 KB, 735x884)
21 KB
21 KB JPG
Spot the bug:
t->l = strlen(chars) + (incl_null) ? 1 : 0;
t->c = malloc(t->l);
strncpy(t->c, chars, t->l);
>>
>>102791618
>strlen(chars) + (incl_null) ? 1 : 0;
What's the value of incl_null?
>>
>>102791618
strlen(chars) + (incl_null)
is the condition so t->l is either 1 or 0.
Use more brackets dumbo.
>>
>>102791618
>t->l = strlen(chars) + incl_null;
>>
>>102791618
you are using malloc
>>
>made a perl script that scans our 100gb of apache logs faster than python, powershell (kek) and javashit other coworkers where using
>literally a big regex and a hash
>treat me as as some sort of alien now.
>>
>>102791618
I asked AI.
In summary, the bug in this code lies primarily in how operator precedence affects the calculation of string length when including a null terminator.
Bold Answer: The bug is due to incorrect operator precedence in calculating string length; it should be corrected to: t->l = strlen(chars) + (incl_null ? 1 : 0);
>>
>>102791618
Filtered by precedence
>>
File: stfu.jpg (88 KB, 900x900)
88 KB
88 KB JPG
>>102792126
>>
what do you think about visual comments in code
>>
>>102791656
it was always 1
>>102791681
yup... I thought the braces around incl_null would be magnetic or sth...
>>102791859
oy, don't call out my jeetcode
>>102791905
I don't actually, this was part of my db code and the allocator currently uses a 1kb buffer on the stack.
>>
File: blinklol.webm (1.71 MB, 720x796)
1.71 MB
1.71 MB WEBM
Nice, only took me a day for the blinky. I fuckin love proprietary FPGA tooling now!!!

Actually wasn't that bad, just had to figure out a lil here and there

Just had some terry-style noodles and now we're kooding H A R D. Gotta think for a minute if I want to port my current VHDL kode first or try to get the risc-v cpus up and rooning
>>
>>102781917
>Wconversion
using this warning is a terrible idea, casting will explicitly disable UBsan's ability to check for overflow (including ftrapv I think too, but I have not tested it, I also do this for unsigned numbers which is only supported on clang using a special sanitizer flag).
my approach is to use clang-tidy because GCC's pusp+pop pragma suppression uses 2x more code compared to clang-tidy's // NOLINT and // NOLINTNEXTLINE
Yep my code has like 200+ NOLINT suppressions, it's unfortunate that 99% of the time I want ubsan to detect the overflow, I absolutely never want to cast the number.
>>
Getting back into c++, made a short game with dice, but I wanted to have dice that weren't just 1 to n-sides (like Mario Party). Since multidimensional arrays are required to have uniform lengths, would the "best" solution be to use a global vector with my predefined dice for a named struct call like this:

std::vector<std::vector<int>> global_die_list = {
{1,2,3,4,5,6},
{1,1,2,3,5,8},
{1,1,1,10},
{2,4,6},
{-10,10}
};

struct die {
std::uniform_int_distribution<int> die_sides;
std::vector<int> die_values;
};

...

// Creating a die variable based on the die in the nth index

die my_die{std::uniform_int_distribution<int>(0, global_die_list[n].size() - 1), global_die_list[n]};
>>
>>102792574
>std::vector<std::vector
NGMI
>global_die_list[n].size() - 1
Unsafe, maybe UB even.
>>
>>102792744
>Unsafe
buy an ad
>>
>>102792892
rust branelet confirmed
>>
I have a C library that I'd like to use from a language where I have to think less about memory management, what should I pick?
>>
>>102792574
the "best" solution is not try to jam a square peg in a round hole
>>
>>102791514
the problem with using kernel level mapping is that it's not faster than malloc, so nobody cares.
you can use malloc for an arena, or whatever datastructure that makes sense (for example std::deque).
>I need a continuous array of memory
OK, but is it faster?
>It's faster because obviously a continuous array of memory is faster!
Benchmark it.
There are situations where just allocating all the memory upfront may take a second, but it's worth it for the performance during runtime. This is done in AI LLM runtimes, you already know the amount of vram or RAM needed to load the model with the context, you just allocate everything, why would you manually commit and decommit when it affects the tokens per second during runtime and do you REALLY want to use the memory all the way up until the OS starts throwing OOM errors? You could just use less memory, and it would let your PC continue to function, you don't need to worry about other applications getting OOM errors because they are not coded to handle it.
I just want to see a real world example where your code is faster than malloc (with full source code). I don't care about realloc or free, I just want a benchmark allocating memory using a VirtualAlloc commits vs giant malloc vs chunked heap (pointer array to chunks), and a benchmark the cost of whatever compute/access you are doing on that array and chunks.
>BUT I CARE ABOUT THE START UP COST, YOU CANT JUST ALLOCATE 50% OF TOTAL RAM AND WASTE 5 SECONDS ALLOCATING 10GB WHEN I MIGHT ONLY NEED 1GB, I NEED 100% OF THE RAM JUST IN CASE.
a data structure that chunks malloc does the job, a potential problem is maybe the cost of double de-reference is high (std::deque might have a solution), but that could be avoided by making the chunks big enough so the array of pointers fit into L1 cache, so like 100mb per chunk or something (but I don't know, it's possible the chunk size does not affect the speed).
>>
>>102778837
The more sleep deprived I'm the cooler coding becomes.

Getting that speed with C++ or GO in python scripts, yeah that;'s the right speed. On Monday I will benchmark that at work.
>>
Test

<code> Test </code>
>>
Test 2.0

 Test 2.0 
>>
>>102793080
Wow, what unprecedented advice that clearly and demonstratively proves everything you're trying to say.
>>
public void showStoredValue() 
{
String filename = "storedValues";
TextView txtViewAnswer = findViewById(R.id.textView9);
String fileContents = "Hello world!";


//create file
try (FileOutputStream fos = (myactivity.this).openFileOutput(filename, Context.MODE_PRIVATE)) {
fos.write(fileContents.getBytes("UTF-16"));
} catch (FileNotFoundException ex){

}


try {
FileInputStream fis = (myactivity.this).openFileInput(filename);
InputStreamReader inputStreamReader =
new InputStreamReader(fis, StandardCharsets.UTF_8);
StringBuilder stringBuilder = new StringBuilder();


try (BufferedReader reader = new BufferedReader(inputStreamReader)) {
line = reader.readLine();
while (line != null) {
stringBuilder.append(line).append('\n');
line = reader.readLine();
txtViewAnswer.setText(line);
}
} catch (IOException e) {
// Error occurred when opening file
} finally {
String contents = stringBuilder.toString();
}
} catch (FileNotFoundException ex){}

}

>>
>>102794227
This code collpases when called, I'm not sure why.

I'm having trouble with storage in android studio. The documentation has less information than I would wish, and I guess that has to do with my lack of java knowledge.
>>
>>102793331
>use a segmented memory model
no, retard

/discussion
>>
>>102778837
>including sys/mman.h
>uh no sweety mremap is not defined
what?
>>
>>102794263
Read the manpage.
#define _GNU_SOURCE
>>
>>102794317
why in the world is that not defined in glibc?
>>
>literally doesnt work
>>
>>102794252
what difference does it make?
>>
>>102794547
algorithms get more complicated for no reason
>just malloc a bigger chunk bro
recursively invalidates your theory
>>
for some fucking reason /usr/include/bits/mman-linux.h doesnt have the mremap definitions, i think my ssd is failing and i am in the third world with nowhere to get nonvolatile media

guess the fbi is going to steal more of my code, not that this time it matters
>>
>>102794456
mremap is a Linux extension, so you have to explicitly opt into using it. See feature_test_macros(7).
>>
>>102794599
You sure it's not in /usr/include/sys/mman.h?
>>
File: 1726931542515544.png (251 KB, 1232x1268)
251 KB
251 KB PNG
Numpy as a graphics API?
>>
>>102794585
If you used C++ this would not be an issue.
But i'm sure you could use macros to make it work exactly the same as an array.
>you can't memcpy or memset or qsort etc
The most laziest programmer, these are all solvable problems.
You could just use C++ and it would be a non-issue.
>C++ is slow
If you look hard enough, i'm sure you can find a C++ container library that will not zero-initialize the data, which would let C++ deque / vector run as fast as malloc. Or better, you could just use a growable pool allocator if you don't care about treating the data as a list of same-type objects.
>more complicated
Your VirtualAlloc code is already complicated, you do not understand what simple code is. And because there are no benchmarks, your code isn't faster. People who actually care about speed will benchmark their code. You can't predict performance, the most smartest people who understand assembly don't even understand why sometimes running a branch to jump over 1 instruction is faster than branchless code.
>>
>>102781914
It was because I used int main() in entry.c, instead of WinAPI WinMain(). I was an idiot.
>>
>>102794833
>not wWinMain
>>
>>102793331
>kernel level mapping is that it's not faster than malloc
Byte-for-byte it is.

>OK, but is it faster?
BYTE-FOR-BYTE IT IS.

>Benchmark it.
See picrel.

I'm not going to bother with the rest of your post since it's just complete drivel.
>>
how do you map something like a gpu resource into memory if theoretically all memory addresses could be valid physical memory? does the os set aside certain ranges for virtual addressing shenanigans?
>>
File: sepples_proof.png (9 KB, 840x320)
9 KB
9 KB PNG
>>102794718
>If you used C++ this would not be an issue.
Nigger, you have no idea how C++ works under the hood. It just uses (another, transparent) wrapper around malloc/free.

>And because there are no benchmarks, your code isn't faster.
You are a complete crackpot.
>>
>>102794718
no i am not going to use the STL
also what in the fucking world are you talking about? the STL doesn't do the magic you think it does, it just wastes more processing time to copy your shit around
>>
>>102794938
the cache controller and pci host bus worry about making a linear array of memory out of all the blocks of memory in the system
>>
basically it is transparent to the OS and even firmware, they just give you whatever addresses they feel like, though competent developers (not GRUB and Linux) usually reserve all non EFI_CONVENTIONAL away from userspace
>>
>>102778837
I was thinking about learning pascal. How does a procedure differ from a function? Is it literally just a function that has no input or return?
>>
>>102796057
think about reading a book
>>
>>102796076
which one
>>
>>102794921
Byte-for-byte is a dumb metric to use here.
What matters is whether you're doing "small" or "large" allocations. For "large" allocations, that is ones that are a multiple of the page size, the kernel allocators are preferable. For "small" allocations (which predominate in many programs, but collect your own damn statistics for your own programs) the wrapped version that is malloc() is better. Except on Windows where malloc() has a shitty implementation for some reason.
You can certainly beat the speed of malloc() in some cases, especially if almost all your allocations are the same size.
>>
>>102794251
Bump
>>
>>102794921
what do you mean byte for byte?
I feel like you are just trolling when you post that benchmark because it's the most cryptic benchmark I have ever seen, you aren't even comparing anything, and I don't even want you to show the code because it's pointless, like I said what are you even comparing?
Use timers and print the metrics, make sure the code isn't optimized out, and show code and build flags.
I just don't know what sort of work you are doing, if you told me you were doing Fibonacci, I could write a benchmark that compares your shitty VirtualAlloc vs std::deque if you want.
>>
>>102796333
>For "small" allocations (which predominate in many programs, but collect your own damn statistics for your own programs) the wrapped version that is malloc() is better.
Bullshit. malloc has considerable per-call overhead even if you discount the locks and unlocks that it has to perform, and you'd know that if you had just looked at any implementation out there, which you haven't because you're a complete crackpot: https://github.com/lattera/glibc/blob/master/malloc/malloc.c#L3011

And now fuck off to whatever filthy hole you crawled out of.
>>
>>102796448
>like I said what are you even comparing?
Like I said: you'd know that if you had just looked at any implementation out there: >>102796455
>>
>>102796485
Ok I'm the retard I guess? could you explain what you are comparing against?
What is the time spent for X and the time spent for Y?
>Just READ, clearly the VirtualAlloc has fewer cycles than malloc!
I actually can't, your post is absolutely meaningless, I don't know why you are so lazy you can't just use a timer and show the code.
I can't even tell if you are reserving the memory or if you are committing it with virtualAlloc, or if you are even calling VirtualAlloc since anything could be calling it, or if you are building with optimizations or not, and if you are reserving the memory, I can't tell how much is being spent committing it while you commit it.
>>
Sucks to be you, but you've already received all the attention a crackpot like you deserves.
>>
>>102796654
I only care about benchmarks, why do you like talking so much like you know everything when you are too lazy to test your own theories?
Did I strike a nerve with you because you are reserving 1gb of memory using VirtualAlloc but you forgot to measure how much it takes to commit it?
>>
the byte per byte argument is retarded since malloc is faster due to the segmentation faults being resolved dynamically, fucking up your task context

malloc is still garbage git gud retards
>>
>>102793067
Python FFI is pretty easy
>>
>>102796908
"But have you counted the NuMbEr oF cYcLeS??!?!?!!!!"
Of course malloc() is slower than just calling into the kernel, because malloc() does exactly that in some cases! But in some (many, typically) cases, it doesn't need to do that, saving a (set of) context switch(es).
On the other hand, the standard malloc() can be beaten in many cases in practice. But then I've done collecting the statistics (for my apps) on sizes of allocations and which threads do the allocation and deallocation, so I know exactly which shortcuts I can take. I dunno about your code; it's literally not my fucking problem.
>>
>>102794227
Is there a particular reason for not using an OutputStreamWriter? Or for not having the FileInputStream controlled by a try-with-resources?
Also, you're storing the string from the stringBuilder in a local variable that's immediately thrown away; I'm pretty sure that's not what sensible code wants.
>>
>>102797125
>my code is Impossible to maintain
i see, fuck off
>>
>>102797252
Not an argument.
And my code is probably running on your computer right now, so I think it is maintainable despite you believing otherwise.
>>
>>102797268
Name the program and I'll get rid of it, even if it breaks the system. No way am I letting your shitcode rape my CPU.
>>
>>102797293
ntdll.dll
>>
File: ntdll.png (2 KB, 252x92)
2 KB
2 KB PNG
>>102797391
Done. What's next?
>>
>>102797444
bro you just posted your password you're gonna get doxxed
>>
>>102796057
procedures can have input arguments, they just don't return anything. essentially they're void functions
>>
>>102797471
Did you hit the absinthe again?
>>
>>102797495
im logging into your 4chan account right now
>>
My bad. Not absinthe, but pure methanol.
>>
>>102797391
imagine using shitdows
>>
>>102778837
so i ported the code over to gcc
//line
ENUM_NIGGER_KILLER TND = TND_NETANJAHU_IS_A_PEDERASY;
variable = TND;
//another two lines
definition_settings NANCY_PALOSI_SUCKED_JOE_BIDEN_OFF = NPCJBO_BILLIONS_OF_DOLLARS;
somevar = NANCY_PALOSI_SUCKED_JOE_BIDEN_OFF;
//...

wow I love modern C!

so anyway
>compiler is hallucinating to the point of resembling chatgpt, ignoring my C code completely
so yeah i think the culprit is
>noreturn function does return
which i cant fucking solve, so i guess i will have to waste 7 bytes for
mov $0x00,%rax # thank you GCC, the GNU optimizing compiler collection
# leave
mov %rbp,%rsp
pop %rbp # truly the most advanced compiler
ret

times some 300 error functions
>>
Anyone know why if I have two versions of imagehlp.dll loaded with LoadLibraryA (it's a long story, apparently directX tries to load it as well but that version it loads is incompatible with an older version that I have to use with another library) that the StackWalk method starts fucking up?
>>
>>102797726
You sound mentally ill.
>>
>>102782888
whats the font
>>
>>102797758
newfag

>>102797777
witnessed
>>
>>102797727
can you send me imagehlp.dll through pastebin btw?
i have procrastinated setting up a windows vm to finish a project and i am not going to stop
>>
>implying I'd listen to mentally ill people
>>
>>102797727
why do you have two versions of imagehlp?? why do you have to use an older version??
>>
>>102797797
cant find the font :^(
>>
>>102797727
just use C++20 and use <stacktrace>
it is missing advanced features (Getting the context of a suspended thread and dumping the stack) but it works well enough for my purposes.
>>
>>102797805
huh, which version? there are a few different versions
>>102797830
this is all I know: if I use the one that DirectX uses then my library doesn't work and if I use the one that came with my library then DirectX doesn't work. If I load them both (different handles) then everything works except I can't walk the stack anymore for some reason.
>>
>>102797897
No, I need the EBP registers
>>
>>102797917
what library is it and why is it packaging its own imagehlp? tf?
>>
>>102797963
>why is it packaging its own imagehlp?
Presumably because the new one doesn't work with it??
>>
>>102797993
imagehlp and other dbg help shit are designed to be backwards compatible. if previous version functionality is needed, this func should be used https://learn.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagehlpapiversionex
>>
>>102797777
Checked.
Font is Terminus.
>>
>>102798047
they return the same value 4.0 r5 for both dll files but they are clearly not the same dll file at all
>>
Made my first small C++ project today. What a damn nice language… can‘t believe it‘s so niche now
>>
>>102797917
any one on a 64bit system really
>>
>>102797830
>>102797963
>>102798047
welp i fixed it, it's fucking magic it has to be in this EXACT order and combined with the funky look up based on path vs no path and reusing the handle for the first base name yadda yadda. Clearly the order does matter, but why it matters it must be due to the way that the dll tries to cross-reference each other that I need a specific dbghelp to always be the one that gets looked up internally while I need the system32 version of imagehelp to be the one that gets looked up
    dbghelpdll2 = LoadLibraryA("assets\\binaries\\dbghelp.dll");
imghelpdll = LoadLibraryA("imagehlp.dll");
dbghelpdll = LoadLibraryA("dbghelp.dll");
imghelpdll2 = LoadLibraryA("assets\\binaries\\imagehlp.dll");
>>
>>102798927
what the fuck.
>>
if I am doing unity build where should I place my globals?
in .h files?
>>
File: 1719667094695292.jpg (32 KB, 540x405)
32 KB
32 KB JPG
which is better for backend, C# or Python? im leaning C# because i fucking hate python
>>
>>102797249
Thanks anon.

I'm going with it tomorrow
>>
File deleted.
Got a object-oriented design interview coming up. I have the design patterns book by the gang of four; anything else I should be studying?
>>
>>102799278
have you ever written a solo project or are you staff?
if not, why the fuck are they interviewing code monkeys on design, surreal
>>
>>102799341
This is for an entry-level position
>>
>>102799402
I dont have anything against you brother

But like why are you not being interviewed on implementing algorithms and tested on not being a fraud through writing a simple program? Muh OOP design sounds ridiculous to me, not only because of above but also because OOP and 'design*' never stand right next to each other
>>
>>102798941
My thoughts exactly.

On another note. Any idea why sometimes incremental builds mess up the stack walk but a full rebuild always works? Is there a optimization setting somewhere in the compiler that could mess with the stack registers to make it compile faster?
>>
>>102799565
define "messing up the stack walk", incremental building shouldnt affect code gen.
>>
>>102799603
Make a few changes.
Press Local Windows Debugger
StackWalk returns 0
Stop debugging
Go in Solution Explorer
Right Click the file I just changed and click Compile
It recompiles the file (turns out I don't even have to do a full rebuild)
Now StackWalk returns true

/INCREMENTAL:NO is set but it's almost acting like it's still on

I'm inclined to think that it's probably a bug related to how hacky this all is but I was just wondering off the cuff if there was some obvious things to try.
>>
File: pino.jpg (28 KB, 400x400)
28 KB
28 KB JPG
>>102780862
Stop or you will live under the sea.
>>
I got bunch of static data (bunch of arrays with numbers) I am going to do a lot of comparisons against in my C program
I am not sure how to organize this in my program for dx and efficiency
do I just make static struct with all that data?
>>
>get close to finishing my project, ie. ready for initial release
>suddenly get the urge to rewrite the project in a different language/framework
every time
>>
How long has Notepadqq been such a lump of shit?
I try using it right after installing, it crashes after like 15 seconds.
Somehow find out it's because of autosave, so I disable it and move on.
I switch tabs between multiple files, and it freezes completely.

I've been using vim out of sheer habit until now, but I want to upgrade to something a bit more feature complete. (or in the case of notepadqq, less memorization heavy)
Is there any decent Neovim pre-config out there?
>>
>>102799751
you can do that, would you prefer the data to be compiled in to the executable? you could just define a static array and fill it with data from a file instead.
>>
This is the complete opposite of what I expected.
>>
File: 1668612346074223.jpg (87 KB, 640x633)
87 KB
87 KB JPG
>>102799897
>benchmarking python
>>
>>102799897
the first time you write it has to dynamically link you bozo
>>
>>102799991
How's your giga optimized fizzbuzz coming along?

>>102799999
I see.
>>
I'm building a non-AI chatbot in Rust
>>
What's the most minimal Android app development setup? I want to make software for my Android phone but I don't want to download some bigass IDE to do it.
>>
>>102800646
>I want to make software for my Android phone
>but I don't want to download some bigass IDE to do it.
pick one
>>
>>102800697
wut
>>
File: 1719018080790938.png (69 KB, 976x317)
69 KB
69 KB PNG
>A Tour of C++ (3rd edition) p.96
Why the fuck is he passing a unique_ptr by reference instead of by Shape*?
If I'm understanding correctly, he can't pass it by Shape& because the unique_ptr might be null.
>>
>>102800697
I want to pick both.
>>
>>102800822
what a shitlang
>>
>>102800822
1. there is no way a null pointer got pushed to the vector and the ranged based iterator won't iterate out of bounds so for an example there is no obvious need for error checking.
2. as for why by reference, because that's what for_each does, it passes each element in v to the function by value or by reference. There is nothing that I am of aware that will automatically call .get() on the unique_ptr before passing it to the function you would have to make your own utility function to do that.
>>
>>102778837
Finishing up a blog site with links to domain posts + cv + personal projects for my switch to contracting (senior dev => self-employed with my own company)
>>
>>102800822
Please, brother, can you spare some brackets?
>>
>>102779565
The main pull for Go when it comes to this kind of stuff is:
- deployments are brain dead easy
- no dependency mucking
- fast af
- no need for gunicorn

If they like Django and the admin section and all that it'll be a tough sell though
>>
porting a C program to WASM
is it still a pain in the ass to call a C function with a JS array?
>>
>>102800852
>1. there is no way a null pointer got pushed to the vector and the ranged based iterator won't iterate out of bounds so for an example there is no obvious need for error checking.
Okay but, in principle, you *can't* pass your unique_ptr<something> by something& because the pointer might be null. In principle, we don't know whether read_shape may return nullptr.
In general, if you have a vector<unique_ptr<something>> you can't use for_each with something& in the sense that the language shouldn't even let you. That's what I wanted to say.
>2. as for why by reference, because that's what for_each does, it passes each element in v to the function by value or by reference.
I understand, but isn't it bad design? If you don't want ownership transfer, you typically get a raw pointer instead of a reference to the unique_ptr. To be honest, the whole concept of references to unique_ptr seems meaningless, weird, and conceptually wrong to me.
>>
>>102800880
Nobody uses django and gunicorn nowadays. It's all outdated WSGI crap. The modern approach is bare aiohttp.web or ASGI. The ASGI shit seems more maintained, but it follows some of the same bad decisions WSGI had.
>>
>>102800998
>>1. there is no way a null pointer got pushed to the vector and the ranged based iterator won't iterate out of bounds so for an example there is no obvious need for error checking.
>Okay but, in principle, you *can't* pass your unique_ptr<something> by something& because the pointer might be null. In principle, we don't know whether read_shape may return nullptr.
in principle you could, i get that you're hung up on the fact that you have to dereference a null pointer to get a reference but it's no different than calling operator-> on an empty unique_ptr, so nothing is gained
>In general, if you have a vector<unique_ptr<something>> you can't use for_each with something& in the sense that the language shouldn't even let you. That's what I wanted to say.
>>2. as for why by reference, because that's what for_each does, it passes each element in v to the function by value or by reference.
>I understand, but isn't it bad design? If you don't want ownership transfer, you typically get a raw pointer instead of a reference to the unique_ptr. To be honest, the whole concept of references to unique_ptr seems meaningless, weird, and conceptually wrong to me.
how is it meaningless? unique_ptr expresses ownership semantics the example is trivial and demonstrates how for_each works which is a nice bonus. You are hung up on the fact that he is using a standard library method instead of something hand rolled, you're hung up on the difference between copying a pointer out of unique_ptr and making what is essentially a reference to a pointer.
>>
>>102800862
what did you use?
>>
>>102801112
I don't think we are understanding each other. Let's take a step back.
>We wanna call the method draw() for every object in a vector.
>The vector is polymorphic (e.g., a shape can be a square or a circle) so we need it to be a vector of pointers.
>In modern c++, instead of making a vector of (raw) pointer you should make a vector of unique_ptr so you can express ownership and forget about delete
So, we wanna call obj->draw() for every object in vector, but what's the type of obj?
In principle, it should be either shape* or shape& because "ownership is none of our business". In this specific case, I suppose that shape* is what makes the most sense.
What I'm trying to make clear is that the functor in the for_each (i.e., a lambda, a function object, or a function) has no reason to know that we are using unique_ptr; that's an implementation detail, and it shouldn't be exposed.

>You're hung up on the difference between copying a pointer out of unique_ptr and making what is essentially a reference to a pointer.
Indeed, the latter doesn't look like good practice at all. I get that in this specify toy example the for_each and the vector are two lines apart and it's not a big deal, but in principle the functor in the for_each (the "do the printing" object/function) shouldn't know the owner.
>>
>>102801306
>"ownership is none of our business"
says who?
consider a functor that wants to delete the object that the current unique_ptr owns and replaces it with something else.
>>
>>102800646
Android's native UIs are stored in XML files, so if you're absolutely fucking desperate, you can write those by hand. It's gonna suck absolute ass, though.
If you're not using native UIs because you're relying on some game library like SDL or a total abstraction like React Native, then you pretty much only need the Android SDK and NDK.
>>
>>102801385
I'm autistic enough to write HTML by hand. Surely it won't be harder than that?
>>
>>102801413
Well, I guess it's a matter of how autistic you are. I also tend to write my HTML by hand. The thing with Android's UI layouts is that each entry takes like 5 XML attributes at minimum, and they also use a lot of references to other files. So kinda like HTML+CSS, where the style is defined elsewhere, except that you can also move text and a lot of other stuff into separate files.
>>
>>102799462
t. unemployed

>>102799278
just be good with standard API stuff
>>
>>102801385
If only there was a way to write programs for Android and IOS 100% purely in C or C++
>>
File: SCIP.gif (669 KB, 720x405)
669 KB
669 KB GIF
>>
>>102779332
The correct opinion.
>>
Any datashitters in here? I found a book called "An Introduction to Statistical Learning" is this good enough?
>>
Trying to understand the Chain of Responsibility pattern, but the one example i keep seeing seems totally inappropriate. It's a web server request handler example. The Handler interface is defined as (Request -> Response). One of the handlers performs request authentication, and rejects service by responding with an error if authentication fails; otherwise, the next Handler is called with that same request.
I have a few problems with it, that i can't find any solutions to by googling the usual sources:
1. The process of authentication produces authentication data, or the "user" data, if you will. That data might be useful in the subsequent handlers, yet i don't see a way to pass it without introducing type-unsafe code, such adding a nullable attribute to the request, or bundling the request with a generic map that may or may not contain the user data for a given key. With this approach, the other handlers' code will be littered with type casts and/or null checks.
2. The web request itself is usually stateful. That means reading or writing will affect the other Handlers in the chain in unpredictable ways. If one of the handlers reads the request body, it must be preserved in an additional buffer for other handlers to be able to read the same data.
>>
>>102801904
>filename
chat is this reel
>>
>>102802729
Spelling is hard
>>
I need to figure out a way for someone to prove they have a file, but said file is encrypted and they don't have the password (they're not meant to). Obviously I could just ask them for a checksum, but this verification should be performed regularly, and they could just modify their part of the app to always report the correct value. What I thought about is generating a random key every time, re-encrypting the file and then hashing it, then giving them the key to do the same. Obviously this is pretty computationally intensive but I think it will work. Is there a better way to do it?
>>
>>102778837
does it make any sense to learn java and then python?
in my head it does in the way that java would teach me to program with order and structure and then I can go to python and code better.
but maybe it's already late to do stuff like that and it's better to go straight to python.
>t. 40 yo boomer who wants to learn coding not for job
>>
>>102802954
Why not use the contents of the file as an IV?
>>
>>102803076
Please, elaborate.
>>
>>102803089
The contents of the file would act as a pre-shared key (PSK) for symmetric encryption. If the decryption of the data they send to you yields nonsense they don't have the original file.
>>
>>102803139
What if the file is huge, though? I'd rather have the test be expensive computationally than transfer potentially as much data as the file itself for each challenge.
>>
>>102803281
>What if the file is huge, though
That's why I said IV. You can hash the file a couple thousand times with a fixed block size and use that as IV for your encryption.
>>
>>102803059
>go to python
>and code better
lol
lmao

python is for just getting things done with no regard for code quality
if you want to just get things done, skip java and jump to python
if you want to write code that will hold up to decades of modifications and requirement changes, focus on java and skip python
>>
>>102803313
That makes sense. Thanks, anon.
>>
>>102799085
Both suck dicks. Both require you buying into the Async/Await idea (the technology from 1800s called "cooperative multitasking") to use networking libraries that are not total trash.
If you want a high level language with automatic memory management, just use Java or Go. If you would like real programming with manual memory management, then choose C or C++ or Rust - everything else is absolutely terrible.
>>
>>102803341
Haskell not mentioned despite having both automatic and manual memory management
>>
>>102778837
>Resources:
>Most important thing you will ever read: >>102778631
>C++ reference:
>en.cppreference.com
>Anal sex tips and tricks:
kek. Made my day.
>>
>>102803336
I think I'll go python then. I rather get some shit done than developing code that will run for decades. thanks.
>>
>>102803341
>Async/Await
>Rust
rust IS async/await, it has no other currency
>>
>>102797726
just use tcc
>>
>>102800092
At least print it 100k times so you eliminate any possible "warmup" as a factor.
Print the times to stderr or grep the times out of the output.
>>
is it fine to use a global variable for functions to use if its something that will stay static like a config and api token?

I don't want to keep having to specify the extra args every single time for most of the functions and its the same thing.
>>
>>102802954
You send salt + range, they return hash((salt, data in that range)).
>>102803953
It's "ok" but you may regret it if you use this pattern more than once or twice in a project and don't have a good system for automatic refactoring.
E.g. it'd definitely get in the way of testing.
>>
Is there a way to "walk" a compressed file without having the entire thing?
I want to know what's inside an archive hosted in a remote HTTP server without downloading it (because it's huge).
>>
>>102804223
Range header.
>>
>>102803853
>rust IS async/await, it has no other currency
The Rust standard library has threads. Just spawn threads. It's 2024.
The only reason to consider async rust is when you need to get the most juice possible in very specific workloads. It's the only language i would consider if i needed to write async coroutines. I still don't understand the rationale of people who pushed async/await into python - you would not want to spend any amount of time optimizing python code, so why not just use native threads for concurrency?
>>
>>102804308
Python can't into threads, sadly
>>
>>102804272
Thanks.
>>
>>102804323
>Python can't into threads, sadly
Why? If all you need is concurrent IO, what is stopping you from spawning hundreds or thousands of threads that spend most of the time blocked on IO?
>>
Are there solidity developers here?
>>
+1 for low-alloc low-level programming. Using std::array everywhere, pools...
>>
>>102805155
>std::array
malloc
>>
>>102805155
>not using reserve-high/commit-low
>>102791514
>>
>>102805161
Does not know what's std::array award
>>
In latex/tikz I can do this:
\foreach \x\y in {2/6,3/5,4/4,5/3,6/2,7/1}{
\foo{\x}{\y}
}

And I can do this:
\foreach \x in {2,3,...,7}{
\bar{\x}{\y}
}

So why can't I do this:
\foreach \x\y in {2/6,3/5,...,7/1}{
\foo{\x}{\y}
}

?
Am I missing something or is it just not possible? (I also tried .../... but no dice)
>>
Forget for a second about the languages that you know, and consider the following:
- you have a variable x referencing a mutable object with a field y set to contain a value
"original value"
;
- you want to perform an operation that will mutate x, setting its field y to contain
"new value"
;
- you also want to perform an operation that will create a copy of that object and shadow the variable x with a reference to the newly created object;

What would be the most concise, non-ambiguous names for these operations?
>>
>>102804335
>>102804223
Here is the code, if anyone needs it.
import requests
import io


def get_file_names(zip_url):
# 1. Request just enough bytes from the end of the file, to get the End of
# central directory record (EOCD)
res = requests.get(zip_url, headers={"Range": "bytes=-100"})

# bytes
content = res.content

pos = content.find(b'\x50\x4b\x05\x06')

# https://en.wikipedia.org/wiki/ZIP_(file_format)#End_of_central_directory_record_(EOCD)
offset = 12
# Size of central directory (bytes) = 4 bytes
# Offset of start of central directory = 4 bytes
# Comment length = 2 bytes

pos += offset

cd_size = int.from_bytes(content[pos:pos+4], "little")
cd_offset = int.from_bytes(content[pos+4:pos+8], "little")
comment_len = int.from_bytes(content[pos+8:pos+10], "little")

res = requests.get(
zip_url,
headers={
"Range": f"bytes={cd_offset}-{cd_offset+cd_size}"
}
)

# https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header_(CDFH)

content = res.content
offset = 0
signature = b'\x50\x4b\x01\x02'

files = []

while content[offset:].find(signature) != -1:
offset += content[offset:].find(signature)
offset += 28

filename_len = int.from_bytes(content[offset:offset+2], "little")

offset -= 28
offset += 46

filename = content[offset:offset+filename_len].decode("cp932")
files.append(filename)
return files

>>
>>102805871
>- you also want to perform an operation that will create a copy of that object with a different value stored in the field y, and shadow the variable x with a reference to the newly created object;
fix
Also, 4chan dropped code tags around x and y. Weird.
>>
File: 9780131103627_1.jpg (40 KB, 484x640)
40 KB
40 KB JPG
Is this still the goat book for learning c ? I want to mess about with some open source linux stuff
>>
>>102806476
ye
>>
File: 1728418057898263.jpg (49 KB, 1024x961)
49 KB
49 KB JPG
I hate having so many options. Why can't I just use loops for everything. I am tired of looking up whether there is alternative option for every little thing I do.
>>
alternatives never scale
>>
>>102806512
ye?
>>
>>102805871
Copy-on-write?
>>
>>102805871
Set x.y
Evaluate _ in an environment with a copied x. "Performing operation" sounds like it has to be a statement, but that's turning the natural interpretation of the process inside out, in that the effects of the shadowing apply all the way to the end of the block, which is outside of the shadowing statement.
>>
>>102805871
linked list
>>
>>102778837
if i include header.h in 5 files will i get multiple definition errors?
i am trying to rename .h to .c after compiling other stuff and then link but i am getting multiple definitions in the linker so i need feedback on if the culprit is something else
>>
when you create a window on windows, is name clashing when you assign a window class name a concern?
>>
File: GZqKRn5WcAcj26C.jpg (195 KB, 1920x1080)
195 KB
195 KB JPG
Finished working on my Triple Triad clone.
Which I'm calling Triple Trap. For obvious reasons.
>>
>>102799897
>benchmarking IO to a terminal
oh dear
>>
>>102808031
nta but why is printing shit out always so goddamn fuckingslow
>>
how do you avoid using a global counter variable that counts the number of actions taken (while also simulaniously displaying it in the terminal updating in real time), when using concurrent threading in python?

I currently use a global counter variable shared between the initilized threads that increments it by +1 for every finished action and see no other way to do this other than a global variable
>>
>>102797249
The program no longer shuts down on execution.
And I managed to make it work.
My logs look full of question marks and the label also shows two question boxes at the beginning, before hello world. I have to figure that out. But seems to go better.

Thanks again

Might post an image later
>>
>thought about giving gcc yet another chance to generate better vector code through intrinsics
>generated code absolutely sucks
I just don't learn my lessons, do I.
>>
>>102809530
What bothers me in particular is that in theory the compiler would be capable of some disgusting optimizations if it was able to track all dependencies and eliminate dead stores and redundancies. In practice it just never fucking happens.
>>
>>102808875
The logs in picrel.

The TextView says Hello world without the '?' characters, but with the two diamond shaped question marks at the beginning.
>>
>>102809530
llvm dabs on gcc so hard it's unreal
>>
>>102809605

code:
public void showStoredValue(View v) {
String filename = "storedValues.txt";
TextView txtViewAnswer = findViewById(R.id.textView9);
String line = "";
String fileContents = "Hello world!";


/*if(){
//access file
try (FileOutputStream fos = (Context.this).openFileOutput(filename, Context.MODE_APPEND)) {
fos.write(fileContents.getBytes("UTF-16"));
}catch(IOException ex){}

} else {*/
//create file

try (FileOutputStream fos = (Context.this).openFileOutput(filename, Context.MODE_PRIVATE)) {
fos.write(fileContents.getBytes("UTF-16"));

} catch (FileNotFoundException ex){

}
catch (IOException ex) {
}
//}

//////////////////////////////////////////////////////
// Reading data

StringBuilder stringBuilder = new StringBuilder();

try ( FileInputStream fis = (Context.this).openFileInput(filename) ) {
InputStreamReader inputStreamReader = new InputStreamReader(fis, StandardCharsets.UTF_8);


try (BufferedReader reader = new BufferedReader(inputStreamReader)) {
line = reader.readLine();
while (line != null) {
stringBuilder.append(line).append('\n');
Log.d("success", line);
txtViewAnswer.setText(line);
line = reader.readLine();

}
} catch (IOException e) {
// Error occurred when opening raw file for reading.

}
inputStreamReader.close();

} catch (IOException ex){

}
}
>>
File: IMG-20241013-WA0000.jpg (35 KB, 791x315)
35 KB
35 KB JPG
>>102809625
Picrel
>>
>>102809619
LLVM has no proper register variables, so it can just suck my cock.
>>
>>102808448
store it in a database
>>
>>102806476
I like Beej better than K&R.
https://beej.us/guide/bgc/html/split/index.html
>>
>>102782820
and??
>>
>>102809625
>>102809641
>"UTF-16"
>UTF_8
>>
>>102801781
What way is that? I'm interested. I'm a C programmer at heart.
>>
>>102808045
Because the system call gets transferred to another process for it to decide what to do with (lots of context switch overhead) and some terminal implementations can be quite slow. I also forget what the buffer size is. For timing purposes, direct to a file (or /dev/null) and be very careful with flushing.
>>
>>102808448
If you want a global counter, you need a global variable somewhere to handle it. You can wrap it inside a class to get the synch right, as classes are effectively global.
>>
>>102810705
Thank you ever so much
>>
>>102778837
Asking for help because i have been suffering, grasping at straws for too long now

int main(uint32_t argc, uint8_t ** argv){
/* SOME LOCAL VARIABLES */
/* MEMORY ALLOCATIONS */

if (memcmp_zs(PROGRAM_NAME,argv[0],strlen(PROGRAM_NAME)) ==0){ --i;} //argv[0] is not the name of the executable when called by strace
for (; i < argc; ++i){
if (memcmp_zs("-i",argv[i],2)==0){
++i;
if (input_file_fd != MAX32BIT){
killed_by_duplicate_input_file();
}
input_file_fd = open(argv[i],O_RDONLY,0); //passing nullptr is not a worry
if (input_file_fd == MAX32BIT){
killed_by_bad_input_file();
}
/* ...}


IN ANOTHER FILE */

//secured for null-ending strings shorter than len
uint32_t memcmp_zs(uint8_t * one, uint8_t * two, uint64_t len){
for (uint64_t i = 0; i < len; ++i){
if (one[i] != two[i]){
return 1;
}
if ( (one[i] == 0) || (two[i] == 0) ){ return 1;}
}
return 0;
}

/* STRACE OUTPUT */
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|21<<MAP_HUGE_SHIFT, -1, 0) = 0x7e83b9000000
mmap(NULL, 49152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7e83b9be0000
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7e83b9bdc000
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7e83b8800000
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7e83b99c7000
mmap(NULL, 98304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7e83b99af000
openat(AT_FDCWD, "-i", O_RDONLY) = -1 ENOENT (No such file or directory)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffffffffffff} ---


/* THE COMMAND LINE */
strace -o log.txt ./PROGRAM_NAME -i /* ITS FUCKING "-i"*/\
SOMEFILE -o nigger


Me retardo?
>>
File: output.png (6 KB, 866x210)
6 KB
6 KB PNG
Maybe, just maybe, I'll leave this comment undeleted so that the next time I want to make variations I don't have to reserve-engineer my entire fucking code incorrectly, god fucking dammit.
>>
well for one the argv[0] check is wrong, != over ==
>>
>>102811684
Are you trolling?
>reinventing strncmp shittily
>using uint32_t and uint8_t as main parameters
>looping through argv until argv[i] == "-i" and then wondering why it's "-i"
If not, then what is the value of "i" when the open call occurs?
>>
>>102811764
stuff like the executable's name being readonly after compilation is silly but no i swear on my soul i am serious, i feel so fucking retarded right now like i dont even know anymore bro
>>
>>102811670
I think the only thing left to already have all I will need in storage is to figure out the private/append-mode condition, checking if the file does already exist, and creating the logic to manage the string building and unbuilding.

Thanks for the help with the issues
>>
omg i didnt see the rest of your post because small window,
>strncmp
i am doing -nostdlib and -ffreestanding
>main parameters
doesnt even give a warning on .c
>looping on argc until it equals "-i"
that is... not what i am doing at all lol, main is 198 lines (pretty small actually)
though...
>does equal "-i"
>++i
like do you see how the assembly output is not even close to my code?
this happens on both -O0 and -O0 -LTO -ffunction-sections (havent tried higher -O)
>>
>>102779798
Either you're a beginner who copied that code from AI or something else is off here.
Whenever your parameters and variables depend on user input, your code must include checks for types, boundaries and exceptions. In this case you should have code that checks argc before trying to use it. GCC isn't doing anything wrong with that code, GCC just isn't an AI code editor who can tell you what is missing from your code. It only checks that your code conforms to the standard, and sometimes more. C is for hackers anyway, if you want safety you run to .NET and C#.
>>
>>102811792
I don't see anything wrong with it, other than your shitty strcmp. Maybe try a clean build? You mention multiple files so you might have forgotten to recompile one.
You should also step through it with gdb to see where exactly it is going wrong.
>>
>>102811928
what the fuck?
after the loop i have a check on 3 vars, config _fd input file fd and output file fd for them being -1 32bit, which call missing... file(), but that doesn't matter because the information i provided should be enough to set off an alarm on the compiler's side
>>
>>102812022
>rebuild everything
i made sure to do that
>You should also step through it with gdb to see where exactly it is going wrong.
i dont see what i could do with gdb though, i cant do instruction by instruction breakpoints and at that point i might as well just read the assembly, but this is not what i should be doing man

really I am just looking for confirmation that something is going wrong with the toolchain so i can reinstall ubuntu with a working compiler, I did a full system update but idk i am confused
>>
>>102811928
lol
>>
>>102812082
>i dont see what i could do with gdb though
Set a breakpoint on the if statement inside the for loop, and walk through it, line by line. You shouldn't need to do instruction-level breakpoints for this.
I bet that will show you what the problem is. Maybe it's signed integer overflow from you using MAX32BIT instead of -1. Or maybe it's not in the code you posted at all.
>>
>>102812113
i didnt know gdb was that strong, i am looking into it, thank you for the help
>>
>>102812044
No you need to check argc value before trying to use it as a parameter in a for loop, e.g.
if (argc > 0)
for (uint32_t i = 0; i < argc; i++)

Because otherwise if argc is zero then your for loop runs for no reason, yes?
>>
>>102812164
You don't know how for loops work at all. Go back to CS101.
>>
>>102812196
I know how they work you retard. Show/explain where my example code is wrong.
>you can't
>>
>>102812214
Your if condition is completely useless.
>>
>>102812214
>I know how they work
No you don't.
>>
>>102812248
It isn't. Besides you said I don't understand for loops. How does that show in my example? Are you some fucktard trying to troll? Just pretending to be retarded on 4chan?
The if statement is there to make sure the for loop doesn't get called if argc is zero. Don't tell me you're one of those "clever" coders who for example test a value by calling a for loop and testing it there lol. If so, quit coding rn and get a job your brains can handle lol.
>>
>>102812271
Yes I do. I already asked you to show where my example code is wrong. If you knew, you would deliver. Else, you're a pathetic troll.
>>
File: part_of_the_problem.png (363 KB, 828x683)
363 KB
363 KB PNG
>>102812300
>Don't tell me you're one of those "clever" coders who for example test a value by calling a for loop and testing it there lol.
>Checking the same condition twice for no reason.
You are part of the problem.
>>
File: file.png (817 KB, 1595x1261)
817 KB
817 KB PNG
>>102812300
but if argc is 0 then the loop doesn't run anyways
>>
So i used gdb (incredible software by the way)
long dump...
40                      if (memcmp_zs("-i",argv[i],2)==0){
(gdb) next
51 else if (memcmp_zs("-o",argv[i],2)==0){
(gdb) next
61 else if (memcmp_zs("-I",argv[i],2) ==0){
(gdb) next
81 else if (memcmp_zs("-include",argv[i],8) ==0){
(gdb) next
138 else if (memcmp_zs("-conf",argv[i],5)){
(gdb) next
139 ++i;
(gdb) next
140 uint32_t fd = open(argv[i],O_RDONLY,0);
(gdb) next
141 if (fd == MAX32BIT){
(gdb) next
142 killed_by_bad_configuration_file();
(gdb) next
Program received signal SIGSEGV, Segmentation fault.
0x0000555555556e65 in print_integer ()


/* _NORET is currently void because attribute [[noreturn]] wont compile without -fpermissive */
_NORET killed_by_bad_configuration_file(void){
deadly_error("\nCouldnt open the configuration file");
}

#define SHELL_PRINT_BOILER_MACRO(spoken_num)\
if (memcmp((void*)mod_##spoken_num,(void*)"%num",4)){\
shell_print_integer((uint64_t)text_##spoken_num);\
}\
else if (memcmp((void*)mod_##spoken_num,(void*)"%str",4)){\
shell_print_string((uint8_t *)text_##spoken_num);\
}
void shell_print_1(const char * mod_one, uint64_t text_one){
SHELL_PRINT_BOILER_MACRO(one);
}
void log_error(const char * string){
shell_print_1("%str",(uint64_t)string);
}
void deadly_error(const char * string){
log_error(string);
_exit(0);
}

/* memcmp doesnt make any function calls, basically there is no way print_integer could have been called
from the C code logic at least*/
>>
>>102812164
her i was set to 1
>>
>>102812351
He believes that loops have some inherent overheads apart from the check and the jumps that needs to be avoided by doing one check outside the loop first. Which is wrong and shows that he really does not understand loops.
>>
the input was
(gdb) run -i prepro.lol -o nigger
Starting program: /program.bin -i kek.lol -o nigger
>>
>>102812324
I see, you're a troll.
The for loop in my example does not test if argc is greater than zero. It seems to be you who doesn't know how for loops work. It only compares values i and argc, it does not test if argc is greater than zero. The if statement checks if argc is greater than zero and calls the for loop only if argc is greater than zero. If argc is zero the for loop doesn't get called at all. There is no checking argc twice.
You clearly don't code for a living.
>>
>>102812351
That's the point. Is everyone a legit retard here?
>>
>>102812428
Go away.
>>
oh my fucking god
else if (memcmp_zs("-conf",argv[i],5))
is missing == 0, kind of embarrassing

though the print_integer stuff s perplexing
>>
>>102812362
>>102812384
So it turns out there was a lot of very relevant code that you neglected to include.
I see two problems here:
>argv[0] is not the name of the executable when called by strace
This is wrong. Delete that if statement.
>else if (memcmp_zs("-conf",argv[i],5)){
There's no == 0 here, so it is entered for i == 0 because the program name doesn't equal "-conf".

As for why it segfaults, who knows. Probably just your shit code.
>>
>>102812428
You are truly retarded. I kneel.
>>
>>102812363
My code was an example showing why you must check user fed values before using them in e.g. loop parameters because these are some of the most common bugs in code. This is why they teach this in schools already. Brainlets ITT would not pass basic programming courses.
>>
>>102812372
This guy is a troll or a legit retard.
>>
deleted targets, re-make'd, same exact lines are being run
>>
>>102812494
argc is not a user fed value, you absolute nitwit. And even if you couldn't trust it, this loop would still not execute if argc was negative.
for (int i = 0; i < argc; i++)

If you can't see why that is, go start digging ditches. You have the perfect intellect for it.
>>
>>102812479
>argv[0] strace
yeah, i memed somewhere along the line
>Probably just your shit code.
elaborate? all the way upstream nothing could have called the function that segfaulted
>>
File: file.png (203 KB, 1069x652)
203 KB
203 KB PNG
>>102812494
argc and argv are not user fed values, nor are they arbitrary to the point of needing to do sanity checks. the C standard outlines the rules for these variables
>>
>>102812560
>all the way upstream nothing could have called the function that segfaulted
I can't see your code, I have no idea why that happened.
But if you want to find out, run it under gdb again but use "step" instead of "next" for that last line. Something in your killled_by_bad_configuration_file function isn't right. If that looks fine, then you need to look at the assembly.
>>
>>102812462
>>102812493
Please retards. Do you think the for loop in my example tests if argc is greater than zero? Because it doesn't. The statement is literally equal to
i = 0;
while (i < argc) i++;

So now that you know how for loop works, explain where there is
if (argc > 0)

Or stfu. Idiots.
>>
>>102812606
>>102812362 is scroll-down
forgot to add
void print_string(uint8_t * string, uint32_t doko){
write(doko,string,strlen(string));
}
void shell_print_string(uint8_t * string){
print_string(string,FD_STDOUT);
}
>>
>>102812543
>>102812603
These two posts cancel each other out. Like I said, you're brainlets who need to quit coding.
>>
which prints a text-editor -breaking null byte

this thread has really been productive for me holy
>>
File: SmugWojak4.png (9 KB, 224x250)
9 KB
9 KB PNG
>>102812631
>i = 0
>while (i < argc)
Fucking KEK. Your infant brain can't even into object permanence. As soon as you type "i = 0" you forget what i is.
>>
>>102812674
You're mentally ill and need to have your cranium caved in.
>>
>>102812684
How so? Please explain. Do you understand scope and global variables?
>>
>>102812727
do you understand the transitive property?
>NO
>>
>>102812701
Come here and show how it's done. I'd love to see a basement dwelling actual retard try that.
>>
>>102812164
did you know that if you compile this without optimizations it's worse than removing the if statement, and if you turn optimizations on it results in the exact same output as if you had removed the if statement? I thought that was interesting
>>
File: 1661284023151181.jpg (12 KB, 636x482)
12 KB
12 KB JPG
>>102812745
>not posting his address
>>
ok so basically i had not assigned a value to arena_manager.count and a call to malloc (which i dont check the return of and let OOM do OOM instead) returned -1...

so basically debugger's are le good

Thank you to everyone who helped out
>>
File: gnu.png (18 KB, 144x125)
18 KB
18 KB PNG
>>102812822
Your welcome anon
>>
>>102812730
If you define the int variable as the first parameter in a for loop the variable becomes garbage after loop is done. It does not become garbage if the int variable is defined outside, like how it's done in while loops. As C nor C++ has no GC in the standard, it's quite common to use a global variable for loop iterations. Also keep in mind that high level languages are written for people, not machines. Trying to optimize high level code for the machine is incredibly stupid and a sign of poor education. So when these brainlets try to "optimize" the code by "checking" values within for/while loop parameters, they're only ensuring their unemployment.
>>
>>102812884
>If you define the int variable as the first parameter in a for loop the variable becomes garbage after loop is done.
>high level languages
>C
>>102812701
was right.
>>
>>102812747
Listen, despite what these brainlets are saying, argc is a user fed value. It's an integer value representing the amount of pointers in argv which holds strings that are user fed. More specifically argc and argv are parameters of the main function.
They are absolutely user fed and not known at compile time. This makes them runtime user fed values and the argc parameter should be checked before running any other block of code.
if (argc > 0)

is a common and smart way to do it. You can find it in thousands of C programs.
>>
>>102812992
>the kernel is going to hack my program!
>>
>>102812933
C is a high level language. Annoying prick. You have no friends, no job, no women. All you have is 4chan and you think you're making a difference here lol.
>>
>>102813011
Kernel is the user in this case you dumb fuck. Of course you thought user is always human. KYS.
>>
>What are you working on, /tech/?
Spending an inordinate amount of time implementing features I'm never ever going to need.
>>
>>102813028
the kernal can also modify your application binary if it wants. are you putting guards in all your functions incase one of them gets swapped? are you guarding the guards as well? what if the loader is compromised?
>>
maybe I'm dum but what's the point of an anonymous namespace in c++? wouldn't a function that only exists inside the cpp file already be hidden from the rest of the program anyways?
>>
>>102813197
I think you're someone who learned to code without going to university and you're upset because your opinions are rarely challenged. Reasonable and fairly common safety checks like
if (argc > 0)

causing this much butthurt is not only utterly ridiculous but if you behave like this IRL you'd get sacked real quick. Safety checks and exception handling is a common standard among professional coders and many coders make a living fixing shitty code that checks nothing and just assumes there will be no exceptions and no need for error handling. Simple and effective checks like that cost nothing, no added compile time, runtime isn't hurt by it either. Modern compilers will simply ignore the line if the same check is done elsewhere. It does not hurt anything else but the feelings of 4chan wannabe coders who can't be challenged nor can they open their minds for another way of doing things, even when it's better and indeed commonplace in the modern industry. Not my problem desu, just another reminder to never hire anyone who isn't university educated at least.
>>
>>102813257
type/variable name overloading is my best guess, should be undefined behaviour though because compilers should be free to loop through a globals/locals array or walk backwards in the source, this would need the compiler to be the second kind

>no export
use static?
>>
God. Programming with nvim makes everything so much more fun. I get less autocomplete and such, but I guess that just makes me a better programmer, right ?
>>
>>102813257
>wouldn't a function that only exists inside the cpp file already be hidden from the rest of the program anyways?
no it won't be hidden, will have external linkage by default, anonymous namespaces are intended to replace the idiom of typing static a bajillion times but it turns out that people like typing static for some reason so they kept both ways to do it
>>
>>102813399
>many coders make a living fixing shitty code that checks nothing and just assumes there will be no exceptions and no need for error handling
I hate having to acknowledge this truth.

>just another reminder to never hire anyone who isn't university educated at least.
I was with you until this generalization.
>>
#define CREATE_APPLICATION( app_class ) \
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*/, _In_ LPWSTR /*lpCmdLine*/, _In_ int nCmdShow) \
{ \
return Core::RunApplication( app_class(), L#app_class, hInstance, nCmdShow ); \
}

Looking through some official Microsoft programming examples, is it normal in win32 programming to implement your entry point through a macro or is this some kind of weird unit testing shit or something?
>>
>>102814964
its not normal, but it is when you're microsoft
>>
>>102814964
sort of? wWinMain has a terrible interface, the w prefix for UNICODE is a can of worms in an of itself if you're not familiar with windows programming, hPrevInstance for 16-bit backwards compatibility, hInstance and nCmdShow being pass through values that mean nothing 99.99% of the time, makes sense to hide it.
>>
>>102815201
hPrevInstance is legacy, rest are useful, not so sure about nCmdShow though since I've never seen it contain any value besides SW_DEFAULT

anyways the macro has isn't changing the WinMain signature, just passing off the work somewhere else
>>
>>102815263
>nCmdShow
You can change the value if you launch the program from a script or whatever, like launching a windowed app minimized to do work in the background.
>>
>>102803341
>>102804308
>>102804717
>what is stopping you from spawning hundreds or thousands of threads that spend most of the time blocked on IO?
Are you actually retarded? Theads bring the horrifying universe of deadlocks, mutex, conditional variables, futex, data races, threads synchronization, thread safe queue. Don’t use it. Please don’t use it.
Ever wondered "What if Node JS non blocking I/O could be somehow ported to python?"?
>>
>>102815445
>>102815445
>>102815445



[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.