[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: nu_classic_C_logo.png (137 KB, 2400x2700)
137 KB
137 KB PNG
WIKI: https://wiki.installgentoo.com/wiki//chad/

IRC: #/g/chad at irc.rizon.net
TG: https://t.me/+itOpQDA2Nbk3ZDZh

Don't know how to write C? Start here:
K&R: https://files.catbox.moe/rfhegv.pdf
KING: https://files.catbox.moe/a875c2.pdf
Modern C: https://files.catbox.moe/xeb93p.pdf
>>
File: kot-eyes.jpg (29 KB, 512x512)
29 KB
29 KB JPG
>>102105084
so
its gonna be 3days i shitpost on /g/ already
but otherwise im writing a CV-based thingy graph reader thingy

i got a couple hors left to do but according the 90/10 rule im gonna procrastinate on it longer than it took to develop the rest
anyhoo

i want to benchmark it when im done.
so heres the question:
what to benchmark it against?

i need something faster than sobel.

i asked chode gepetto
i asked jewgle
apparently everyone starts from sobel.

sobel implies a gauss filter
and then to make sense of the mass of contrast points that O(n^2).
my algo beats that so hard its not even fucking funny

does any of you anons know of an algo thats tailor made for that application?
>>
made a template that uses inotify to watch a file, if it changed it recompiles the file with tcc and load functions from it.
>>
>>102105084
Schizo rant: What's common between programming in general and early 19th century chemistry?
--
In my free time, I like to watch documentaries about science, various religions, mathematics, and when I feel especially braindead, I watch Tsoding writing ugly but pragmatic code on Jewtube.
Finished watching 3 hours of documentaries on early chemistry, from the moment it separated from alchemical thoughts to the times of Curie. What was so interesting about people mixing gases and pouring acids on everything imaginable?
--
There were 2 types of chemists. One that would just experiment around, show "tricks" to his wife and children, like how some things burn brightly, or how some gas (CO2) turns the candle off, and freely talk to everyone how they did it... Then the others were those who measure, test the hell out of things, systematize the knowledge and publish papers in their name about it, claiming originality.
--
First kind were Joseph Black, English chemist and a lot of unnamed programmers for that matter.
Second kind were Dmitri Mendeleev, among many others you all heard about, and many other programmers.
--
From good people like John Backus, to more names I don't feel like typing out because you guys know about them (I hope)...
--
Thoughts?
>>
HOW DO I MAKE A WINDOW IN C? AND HOW DO I MAKE A BUTTON? AND HOW TO I PUT A FUNCTION IN THE BUTTON?
>>
>>102105282
you dont
/discussion

seriously tho, if you are making a game, than raylib, otherwise opt for C++ atleast
>>
>>102105084
>a C thread
Don't you mean a /chad/?
>>
>>102105282
Easy. Are you Delphi developer...?
>>
>>102105308
fuck, i copied the pasta wrong
>>
>>102105282
You either use Raylib, and do things you specified there in 20 sloc, or you use XCB/Xlib, achieve same thing in 200 sloc, but you don't leak memory and you use 6% of RAM that Raylib will use. GPU drivers leak memory (used by Raylib), while X11 won't leak if you clean.
>>
>>102105282
https://nappgui.com/en/home/web/home.html
or just gtk
>>
what you're working on
what you're interested in dot jpg
>>
>>102105282
You got a few nice options:
raylib
sdl
gtk
qt6

But to use any of it, you need to read nigger.
>>
>>102105438
no just tell me how to do it
>>
>>102105084
there will be no doxing on this site, so fuck off
>>
>>102105084
Continuing on chemistry, unironically...
>>102105257
How well will you be able to perform programming tasks if you don't have formal knowledge of algorithms and data structures? Is it better to solve problems and tasks systematically or to just screw around and experiment until you solve the problem, from your own intuition?
--
How many known O(n**2) algorithms can be rewritten in O(n*logn)? I mentioned DFT vs FFT performance, at the time of its invention, task that would take with DFT 3 years could be done with FFT in 30 minutes...
I'm working on problem of packing thousands of small PNG images into one big PNG image, solution is straight forward, but you'll get unoptimized results with a lot of wasted space if you don't order those smaller images properly.
--
Formal solution, used for storing lightmaps in statically computed scene lighting is to sort the array of small images by their biggest side (either width or height), and to pack them by order of which of those is larger to X/Y aka U/V order.
That way very little space is wasted between said rectangles (and/or triangles), Cube, game from 2001 uses that approach, and many other games too (that use hybrid lighting). It's efficient, but slow because of sorting (in real time, read: real time).
--
Instead of that, if vertex and index buffers were sorted accordingly, during the model/mesh loading stage, in initialization, you don't have to sort the array of generated images used to assemble a lightmap.
--
Is there a better informal way for solving that kind of problem, which doesn't need to sort the array at all...?
>>
non-conforming scheme
Python style container objects, iterators, module system, LR parser and grammar for Python style source code input
discrete event simulator
just a database of future calls to event handlers to invoke at a given simulated point in the future together with the ability to cancel events before they fire their event handlers
>>
>>102105438
>raylib
nice, but hardly ideal for quick, but robust UIs
>sdl
its a media layer. even more of the same problems
>gtk
i have no clue
>qt6
thats C++

>>102105282
here is something unconventional, but comfy: use Tcl/Tk from your C program
>>
>>102105282
it puts the function in the button
>>
>>102105282
>HOW DO I MAKE A WINDOW IN C?
using win32api on windows and wayland on linux.

>AND HOW DO I MAKE A BUTTON?
you first calculate the length of the text to be drawn as button's title. They you draw a quad first with necessary horizontal and vertical margin to the button title's length.
Then you draw the text characters one by one and this is the most annoying, troublesome part. There are several ways to do it and if you are a beginner, just use freetype2 to generate a font atlas from a ttf. Use it to draw quads with appropriate uv coordinates to render text characters.

>AND HOW TO I PUT A FUNCTION IN THE BUTTON?
if you are going for immediate mode, you can just check if mouse pointer is within the button bounding region inside the application loop(the for or while loop that executes all the stuff every frame) like how dearIMGUI does it. If you are going for retained mode, using callback functions, like how GLFW does it, makes more sense.
>>
Image related is the reason why you should avoid strictly writing cross-platform programs.
If you're on Windows (for some fucking reason) use WinAPI, if you're on Linux, don't bother with other OSes.
It'll save you time and it won't make you go insane...
>>
>>102105749
>C is le portable 111!!!!11118!!!!!88!!&&!!18818181
i wish i could kill that meme with a big rock
>>
>>102105282
>>102105502 (Me)
button_help.c:
// @BAKE gcc $@ -o $*.out $(pkg-config --cflags --libs tcl tk)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <tcl.h>
#include <tk.h>

// our button callback
static
int Tcl_baah(ClientData clientData, Tcl_Interp * interp, int argc, const char * * argv) {
puts("BAAAAAAAH");
return TCL_OK;
}

static
void tcl_run(void) {
Tcl_Interp * interp = Tcl_CreateInterp();
Tcl_Init(interp);
Tk_Init(interp);

Tcl_CreateCommand(interp, "baah", Tcl_baah, (ClientData)NULL, (void (*)())NULL);

/* if only it were past 2023 we could have #embed!
* oh wait...
*/
int result = Tcl_EvalFile(interp, "button_help.tcl");
if (result == TCL_ERROR) {
fprintf(stderr, "Tcl script execution failed: %s\n", Tcl_GetStringResult(interp));
exit(1);
}

Tk_MainLoop();
}

signed main() {
pthread_t tcl_thread;
pthread_create(&tcl_thread, NULL, (void *(*)(void*))tcl_run, (void*)NULL);

// whatever you want
while (1) { ; }
}

button_help.tcl:
package require Tk

wm title . "Button example"
frame .main
pack .main
button .mybutton -text "press me" -command baah
pack .mybutton

this is the easiest way to get a proper button in C. anyone is free to prove me wrong.
>>
>>102105257
Chemistry was pretty nascent in the 19th century, almost indistinguishable from alchemy at that point. It was mostly a hobby for rich people.

Synthetic chemists were like python programmers, they didn't understand why reactions werked, they just did (sometimes) and they got useful things out of them.

Thermo people were like C++ programmers, obsessing over units and taking a million measurements to derive one equation, but ultimately moving the field forward in a more systematic way.
>>
>>102105749
gl.h is already written so you don't need to touch that.
If you want cross platform GUI you can use gtk, it works on windows, there are also other cross platform GUI libraries for C.
>>
>>102105763
Nothing is truly portable, and if it's mostly portable, there's a big price to pay for that, plus it's useless.
>>102105838
I know of course, but I find the idea of cross-platform programs bad, stupid and useless.
>>102105816
Interesting take, would like to read more of comments about it.
>>
>>102105342
Weird. Do you know the source of that leak?
>>
>>102105282
PDCurses or Win32 API
PDCurses is a library for lower level controls or you make your own button. Win32 API is what you are looking for. Literally just Google "Win32 API in C,"
>>
>>102105981
Yes, I use Valgrind on all of my programs, leaks found in most barebones OpenGL and Vulkan renderers (with or without GLFW) are due to GPU drivers, and Raylib, SDL2, alongside that leak few kilobytes of memory internally, during initialization.
What's the difference?
Those GPU drivers leave "still reachable" warning, which isn't 'dangerous' by itself, while simple functions like InitWindow (Raylib) and SDL_Init (SDL) leak memory while initializing some of their internal buffers, which are true leaks.
--
I'm not security expert, and I don't know if and how that could be exploited. But it makes things much harder to test, to check if my part of the code leaks memory, not their, you have to set up 'filters' for Valgrind.
--
It's not about using safe languages to rewrite all drivers, it's just about some fag not bothering to add 1 line of code, 'free (this)'. X11, being boomerware, doesn't have that problem at all (via Xlib/XCB).
Boomers cared about deallocations more, because at that time most kernels didn't clean up after process was killed or crashed, like they do nowdays. If you write pure XCB code, without using GPU, you're safe.
>>
>>102105282
what exactly do you need in your window?
just a couple of buttons? or some more complex widgets?

#include <dg/core/core.h>
#include <dg/base/base.h>
#include <stdlib.h>
#include <string.h>

#define MSG "Click me"

static dg_core_window_t *_w = NULL;
static dg_core_grid_t *_g = NULL;
static dg_core_cell_t *_c = NULL;

static void
_click(dg_core_cell_t *c)
{
printf("button clicked\n");
}

int
main(int argc, char **argv)
{
/* module initialisation */

dg_core_init(argc, argv, NULL, NULL, NULL);
dg_base_init();

/* object instantiation */

_w = dg_core_window_create(DG_CORE_WINDOW_DEFAULT);
_g = dg_core_grid_create(1, 1);
_c = dg_base_button_create();

/* button configuration */

dg_base_button_set_label(_c, MSG);
dg_base_button_set_callback_pressed(_c, _click);

/* grid configuration */

dg_core_grid_set_column_width(_g, 0, strlen(MSG));
dg_core_grid_set_column_growth(_g, 0, 1.0);
dg_core_grid_set_row_growth(_g, 0, 1.0);
dg_core_grid_assign_cell(_g, _c, 0, 0, 1, 1);

/* window configuration */

dg_core_window_push_grid(_w, _g);
dg_core_window_rename(_w, MSG, NULL);
dg_core_window_activate(_w);

/* event loop */

dg_core_loop_run();

return 0;
}
[\code]
Note, this is my old API that I'm deprecating soon because some of my decisions were retarded (like splitting the GUI engine and widget implementations into two modules, "core" and "base" respectively).
>>
>>102106063
1) since its impossible that you compiled GPU drivers with debugging flags, valgrind could be showing false positives
2) leaking memory is "safe", goyim
>>
>>102106063
Thanks anon.
>>
>>102106071
New API (with new namespace) looks like this, but it's not fully operational yet.

#include <cassette/cgui.h>
#include <stdio.h>
#include <string.h>

#define MSG "Click me"

static cgui_cell *_button = CGUI_CELL_PLACEHOLDER;
static cgui_grid *_grid = CGUI_GRID_PLACEHOLDER;
static cgui_window *_window = CGUI_WINDOW_PLACEHOLDER;

static void
_click(cgui_cell *cell)
{
printf("button clicked\n");
}

int
main(int argc, char **argv)
{
/* Setup */

cgui_init(argc, argv);

_window = cgui_window_create();
_grid = cgui_grid_create(1, 1);
_button = cgui_button_create();

/* Button configuration */

cgui_button_set_label(_button, MSG);
cgui_button_on_press(_button, _click);

/* Grid configuration */

cgui_grid_resize_col(_grid, 0, strlen(MSG));
cgui_grid_set_col_flex(_grid, 0, 1.0);
cgui_grid_set_row_flex(_grid, 0, 1.0);
cgui_grid_assign_cell(_grid, _button, 0, 0, 1, 1);

/* Window configuration */

cgui_window_push_grid(_window, _grid);
cgui_window_rename(_window, MSG);
cgui_window_activate(_window);

/* Run */

cgui_run();

return 0;
}
[\code]
>>
>>102106071
As always, amazing work GUI Anon. I just wanted to say that you should definitely keep current naming style.
I'm also writing GUI library, but it's very limited, aimed only at what I want to create with it, it's not general.
There'll be more elements in it when I finish it, separate, like more frames, FFT analizer, checkboxes, cursors, listboxes, etc.
I'll definitely try out your library when I finish some rendering stuff I'm working on, and test it with Valgrind, expect detailed feedback.
>>102106099
> leaking memory is "safe"
Oy vey! D:
>>
>>102105084
Is C a low or a high level language? I'm getting conflicting answers. Some say it's low because High is where you put the Pythons and the C#.
But some also say it's high because if it's not machine code or Assembly, it's not low enough.
>>
>>102106304
does i matter?
as you just stated, it depends on your perspective
its a shrodingers' level language
its in a superposition of being high and low level until you look at it and make your own opinion
>>
hey bros

Let's implement the Tower of Hanoi in an iterative manner instead of using recursion.
>>
>>102106304
it's mid level
>>
>>102106278
Thanks!

>I just wanted to say that you should definitely keep current naming style.
For the most part its unchanged. Main changes are a new namespace, instead of "dg_core_" and "dg_base_", it's now all unified under "cgui_". Callback setters are shorter too, instead of "_set_callback_action" it's "_on_action". + some minor renaming here and there.

>I'll definitely try out your library when I finish some rendering stuff I'm working on, and test it with Valgrind, expect detailed feedback.
Thanks. I've run it through valgrind too. And as long as the appropriate destructor functions are called at the end of the program, the only leaks should be of the "possibly lost" and "still reachable" and are coming from cairo.
>>
>>102106304
its a relative metric and no one specifies that
its high level compared to asm, its low level compared to something like python.
>>
>>102106325
okay, I would like to see that
>>
>>102106453
I never used Cairo, tho have one question about your library in general:
Does it requires linking? I'd like to see how easy is to bind it to Fortran, Ada and use it from assembly.
If you know to use IRC and can tolerate /pol/ humour, join the IRC (if you're not Viktor Kilo also...). (:
>>
>>102105084
Update the telegram link in OP
>>
>>102106641
>Does it requires linking?
Yes because of Cairo. I didn't investigate yet how to make it static. However, two of my other libraries it depends on Cassette-Objects (COBJ) and Cassette-Configuration (CCFG) can be statically built since they only depends on a posix libc.
>Ada
I have thick Ada bindings for COBJ and CCFG (called Cassette-Ada (CADA))w, and plan to create some for the CGUI lib (CGUI) once I'm done with the rewrite.
>>
>>102106641
have you considered that people who shove /pol/posting shit into places it's not meant to be are as annoying as the "lefties and trannies" you're trying to keep out? just post about C, for christ's sake
>>
>>102106858
>and plan to create some for the CGUI lib (CGUI)
and plan to create some for Cassette-Graphics (CGUI, the name of my lib).
I really need to proof-read myself.
>>
>>102106858
Nice, it'll be interesting to play with it. (:
>>102106860
I find the reactions funny, that's why I do it.
--
Interesting reading sources:
> https://blackpawn.com/texts/lightmaps/default.html
> https://blackpawn.com/texts/lensflare/default.html
> https://blackpawn.com/texts/cellular/default.html
It's reminiscent of Kkrieger development, if anyone knows about it nowdays...
>>
>>102105084
apr_status_t pt_make_listener_socket(apr_socket_t **sock,
int port,
apr_pool_t *p) {
apr_status_t rc = APR_EINVAL;
apr_socket_t *s = NULL;
apr_sockaddr_t *sa = NULL;


if (APR_SUCCESS != (rc = apr_sockaddr_info_get(&sa,
NULL,
APR_INET,
port,
0,
p))) {
goto exit_listen;
}
if (APR_SUCCESS != (rc = apr_socket_create(&s,
sa->family,
SOCK_STREAM,
APR_PROTO_TCP,
p))) {
goto exit_listen;
}

// listener blocks forever in main thread
apr_socket_opt_set(s, APR_SO_NONBLOCK, 0);
apr_socket_timeout_set(s, -1);
apr_socket_opt_set(s, APR_SO_REUSEADDR, 1);


if (APR_SUCCESS != (rc = apr_socket_bind(s, sa))) {
goto exit_listen;
}

// socket backlog is 127
if (APR_SUCCESS != (rc = apr_socket_listen(s, 1<<7))) {
goto exit_listen;
}

rc = APR_SUCCESS;
*sock = s;

exit_listen:
return rc;

}
>>
>>102106907
>if anyone knows about it nowdays...
i do
we didnt all die out yet, lmao
>>
>>102105282

Learn to use this header library,
https://github.com/Immediate-Mode-UI/Nuklear
>>
>>102105084
Every minute spent writing C is not spent writing Rust. Wake up people
>>
>>102107039
you say it like its a bad thing...
>>
>>102106860
> delets post becuse of typo
go back
>>
>>102107638
git rm -frfr *
git commit -meme 'Typo'
git push -a
>>
Hello im trying to learn c on my own bought some books. But what do i need download visual studio from ms or visual studio code?
>>
>>102107817
you need a compiler, thats what you cant do without
other than that, i use vscode. no need for the studio part imo
>>
>>102107817
You need to download Notepad++ if you're on Windows, or to use Geany if you're on Linux. Even better, don't use Windows, install Linux Mint, and learn to use it, you need 20 minutes for that...
--
On the note on packing thousands of small images into one big image, my implementation ended up being O(n**3), but it works without recursion (unlike in this link):
> https://blackpawn.com/texts/lightmaps/default.html
    spritesheet = allocate (spells_sprite_format * spells_sprite_format * (int) sizeof (* spritesheet));

for (index = 0; index < spells_sprite_count; ++index) {
for (y = 0; y < spells_sprite_count - 1; ++y) {
for (x = 0; x < spells_sprite_count - y - 1; ++x) {
if (spells_sprite_height [y] > spells_sprite_height [y + 1]) {
swap (& spells_sprite_data [y], & spells_sprite_data [y + 1]);
swap (& spells_sprite_width [y], & spells_sprite_width [y + 1]);
swap (& spells_sprite_height [y], & spells_sprite_height [y + 1]);
}
}
}
}

for (index = inset_x = inset_y = 0; index < spells_sprite_count; ++index) {
int subindex;

inset_x += (index > 0) * spells_sprite_width [index - 1];

if (inset_x >= spells_sprite_format - spells_sprite_width [index]) {
inset_x *= 0;
inset_y += (index > 0) * spells_sprite_height [index];
}

for (y = 0; y < spells_sprite_height [index]; ++y) {
for (x = 0; x < spells_sprite_width [index]; ++x) {
int to = (y + inset_y) * spells_sprite_format + x + inset_x;
int from = y * spells_sprite_width [index] + x;

spritesheet [to] = spells_sprite_data [index] [from];
}
}
}

spells_export_png ("spritesheet.png", spritesheet, spells_sprite_format, spells_sprite_format);
>>
>>102107878
Continuation:
It works, no recursion, no stack-fuckery, even tho 10 MiB on Linux is enough for everybody (tm) with precompiled kernel.
Gonna post results with 1400 images soon hopefully, I think it'd be very slow, due to triple-loop for sorting modified array.
>>
low iq crab thread for mentally ill neets
get a fucking job
>>
>>102105282
#include <windows.h>
>>
>>102107966
t. seething rust clown
>>
File: shot.png (331 KB, 1920x958)
331 KB
331 KB PNG
Also interesting program one Anon recommended long ago... For bump.
>>
>>102105084
I'm making a very minimalistic gameboy emulator, for fun
I got it working to some extent but emulating the PPU timings is causing me headaches
I haven't used C in a long while, it's a bit of a fresh air though
>>
>>102106325
when you solve towers of hanoi the smallest disk always moves on even turns. On odd turns, theres only one possible move, so you do that.
All you need to do is to choose were to move the small disk. I dont remember how this is done.
>>
>>102109379
>>102106325
Ah i remembered, you just rotate the small disk in a fixed orientation every even turn, and make the single possible move with the remaining disks on odd turns. Do that and you solve the towers.
>>
>>102107817
you could use godbolt and onlinegdb as web compilers. on gcc or clang use address sanitizer with -fsanitizer=address (msvc has asan too) and turn on warnings with -Wall -Wextra -Wpedantic (msvc gives warnings by default), and don't forget to turn on -g for debugging. and ubsan can find a couple bugs too fsanitizer=undefined (msvc does not have ubsan, it's not that important and it has false positives), pvs-studio can also find a couple bugs but it's tricky to get the free license working in your IDE (you need to paste a comment at the top of every source file, you can test it in godbolt)
vs studio is fine, vscode is an option if you used cmake (or prefer building using raw commands). if you prefer gcc you could use wsl to run linux in a VM.
If you are dropping money for your coding, I would say clion is a decent IDE if you are willing to use cmake, but note it will eat up 16gb of ram, it's free for students if you have a student email.
the first annoying part of msvc is you need to disable secure function warnings with a flag (printf_s and etc), next asan will give warnings with the default debug flags (ignore or remove them), asan needs DLL's which are not global requires IDE or MSVC dev console or copy dll to exe or add to PATH. Also windows defender will slow down builds so have a folder for all coding and add to exclusions.
if you use cmake or visual studio project, use vcpkg for libraries (it helps with linux too, since you can control the library version, some libraries are not cmake but vcpkg fixes them, and you can build libraries with asan using vcpkg overlay). I use classic mode vcpkg but manifest is easier to use.
I use conemu and I add msvc dev console to context menu so I can open cmd or msvc dev console using right click (for classic mode vcpkg and building with the command line).
if you use cmake you could use cmake presets to add asan as a target, and IDE's will understand the preset.
cmake is difficult but avoiding it will lead to autism
>>
>>102108578
Name anon ? Thx
>>
>>102109857
That's a lot of hints, thanks.
>>
Chads, please tell me if this is retarded:
union u {
struct { int a, b, c; };
int arr[3];
};

It's either that or:
enum {
u_a,
u_b,
u_c,
};
int arr[3];
>>
>>102109857
*also once you get an IDE set up, and you have a project you spent a week or more on, using git is pretty trivial to use, just add files / changes, commit (message), then sync (upload).
The reason for using git is not for paranoia that your files will get lost, it's because the changes you make are sometimes worse than the original code, so with git you could just revert to your original code without needing to rely on keeping your IDE open for days and holding ctrl+z when you need to undo something (which is a very fragile form of source control, which is exactly what I used to do!).
>>
>>102109929
holy shet i didnt know you can use enums that way
both should be equivalent if i understand things correctly
if you wanna be 100% sure write two examples, one for each syntax, and then look at the asm

if these are equivalent, go with whatever you find easier to read.
>>
>>102109929
first one is better, although i think its not standard compliant
>>
(for me it would be the union. thats what unions are for)
>>
The state of the union
>>
>>102109876
radare2. its mainly a reverse engineering tool, but useful for analyzing your ams output too. its also more cool looking than useful (even tho its not useless by any means)
>>
>>102109929
the 1st is genius, i will start using that
>>
>>102109994
>both should be equivalent if i understand things correctly
not equal if you are passing by parameter, but the code is probably inlined so it doesn't matter.
>>
Can somebody tell me why this prints 8 instead of 80? I'm trying to allocate an array of 10 pointers. Why is malloc only allocating space for 1 pointer instead of 10?

void **arr = malloc(10 * sizeof(void *));
printf("size: %ld", sizeof(arr));
>>
>>102110276
this is probably one the best questions you could probably ask bing chat or chatgpt, it's like the first thing you learn about sizeof
>>
>>102110276
no, malloc did allocate space for 10 pointers (unless null was returned). But what sizeof see here is just a pointer to an arbitrary block of memory, and returns the size of that pointer: 8.
>>
>>102110382
Oh yeah, that does make sense. So I guess I need to always keep track of array length in a separate variable then?
>>
>>102110410
yep.
>>
>>102107039
one tranny slipped through the filter
>>
>>102110276
you're effectively doing this:
sizeof(void**)

which equals 8 on a 64 bit os
>>
>>102105282
https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-api-list
>>
>>102107039
The crabs were gay from the start!
>>
>>102110032
badum tss
>>
>>102109929
Why not just use a pointer offset?
>>
>>102110264
aaaaaah
its a matter of pointer vs int

for my defence its high level structs
when im within the true weeds of it, i dont use any abstraction
unless its force inlines
>>
>>102110738
thats supposed to be UB
if you dont care abt portability, you offset, yeah
>packed pointers
if you wanna look it up
>>
>>102110738
>>102110760
>packed pointers
or maybe not
im drunk
but i mean that a struct involves padding, which changes between architectures
a 32 bit arch will pad to 32
a 64 will pad to 64
>>
>>102106907
>It's reminiscent of Kkrieger development, if anyone knows about it nowdays...
A lot of zoomers do, some youtube video about it got popular.
>>
>>102110792
rightfully so
its like, an entire fps fitting in 250kB
that fucking thing deserves to be remembered
merely for being the starting point for a myriad of opti techniques
>>
>>102110814
Wasn't it there for the 96kb contest?
>that fucking thing deserves to be remembered
true
>>
>>102105520
ayo dis nigga uses quads, won't even compile on OpenGL es
>>
>>102109929
first one would be undefined behavior, so obviously the second. it is undefined iso behavior to read a union by any field other than the last field written.
>>
i member
>>
>>102111009
>first one would be undefined behavior,
read the standard you retarded faggot
>>
>>102111009
>undefined behavior
rust shill
>>
>>102110889
something of the sort
you see im genuine about rembering these chads
i go by memory :)
>>
>>102106071
Is that you, anon? https://codeberg.org/fraawlen/cassette-graphics

I like the clean and minimal look.
>>
>>102105935
agreed, one fundamental difference between windows and linux is i/o, on linux when a file is open the kernel assigns it a numerical id for use within your program, on windows it's some opaque data structure, meaning that no i/o library in any high level language can easily work around both without adding overhead
>>
>>102107039
>>/lgbt/
>>
>>102107039
may thy ass fall into eternal slumber, fag
>>
File: concept.png (134 KB, 3840x2160)
134 KB
134 KB PNG
>>102111754
Yes, I also have a mirror of this repo on github.
Currently the default branch is dead, all of the dev happens on the rewrite branch.
>I like the clean and minimal look.
Thanks. Btw, pic related is what I want the end result to look like (at least for the default theme).
>>
>>102105282
GTK, it's basically OOP on top of C
With GTK and Glib/Gio you also get a lot of other nice things like networking and JSON
>>
>>102110276
>>102110410
sizeof only works on static arrays
so [] declarations or constants
the * makes it a pointer which removes the size it had
int a[3] = { 1, 2, 3 };
int* b = a;
sizeof(a) == 12 == 3 * sizeof(int)
sizeof(b) == 8 == sizeof(int*)
>>
>>102107817
>sudo apt install vim tcc
>vim hello_world.c
>tcc hello_world.c
>./a.out
You don't need a full electron OS to do basic things.
>>
>>102110148
cool, does it have a shell like gdb or lldb or do you have to find stuff through context menu hell?
>>
>>102107966
>>>/lgbt/
>>
>>102111967
youre getting there, g
also, thread theme: https://www.youtube.com/watch?v=YOH7WUGBTIc
dont give up even if trannie win time to time, and sometimes you get banned

whenever you get banned
they will be counting down the days til you return
>>
>>102111947
it does have a shell, in tui mode you can access it at the bottom somewhat similar to vim. i believe it should not miss anything that the TUI menus have, but im no expert.
its meant to be "self documenting" with builtin helps; read: no proper documentation for you. in practice this means that finding commands it easy, but understanding concepts used by the program is non-trivial. for example, i have no clue what 'anal' is
>>
>>102111967
Wait is C fucking gay or something?
>>
>>102112748
nah its just trannors doing the "n-bo-u"
there was a trannor pormoting C at a certain point
theres tons of trannors in C right now

the difference is that:
c-trannors at least can pass on an ANONYMOUS FORUM

i can guarantee you that a portion of /c/hads post no picrel in c threads and then post loli or footfetish in the next one.
>>
>>102112903
>post loli or footfetish in the next one.
that's what straight cis white men post, thougheverbait
>>
>>102112920
no
you dont fuck feet
you fuck pussi
and or the bonus hole

also
i posted dis:
>>102105194
why nobody answered that yet
i wanna benchmark
let me go i need to benchmoork

why dont you want me to benchmark
its all i want
is it to much to ask from society
i just want to benchmark, bro
>>
>>102111893
stop talking.
>>
>>102112955
I agree I am analsceptic and pussyphil, however if a woman has nicely nurtured feet any straight man would appreciate it like the rest of her body
>>
>>102113029
i only appreciate it when i can go balls deep
no matter the hoel
im grateful for any hoel xx can give to me

its kinda how relations work
you gotta give back what youre taking
its natural for me but some people could learn it
or i wouldnt be as successful
>>
>>102113029
btw
small women have pussy proportionate to their bodies
if you want loli
try a small woman instead
its gonna satisfy you
i hardly can fit in one
>>
>>102113088
dude my point was that fagets do not post those, lol, not that I wanna fuck one
>>
>>102113116
im drunk
indulge me
BUT
smol wimin bro
thats the fucking secret
if youre a normally constituated man
smol women are fun
not kids
that would be evil
no
wimin
smol wimin
>>
>>102113135
yes, preferably after marriage, just like using pointer after allocating memory to it
>>
>>102107878
are you respecting the maximum texture a targeted GPU can handle? what's the average these days?
>>
>>102113191
if it works for you, it works for you
in fact
i would agree with a puritan society banning sex before marriage
IF theres a caste of sexworkers.
there needs to be a grey zone for everything not normie so to speak, i say
doesnt need to be promoted, or anyhting
doent need to be specially protected either
but i think there should be ways to recycle dysfuntionals, like the army is for murdererers (not dysfunctional per se, but not adapted to society at large- let such people express their instinct in a way thats constructive for society at large)
>>
>>102113227
>>102113246
(bc lets be fucking honest here)
(you go to the army to kill people bc thats a part of your blood, your instinct. its a part of humanity. we shouldnt try to destroy these instincts lest we abandon what we truly are, in the moral sense.
in the practical sense we are not sure we wont encounter species we wont be competing against, in the wider expanse of the galactic ocean)
>>
(in ohter words:)
(our animality is part of our strengths.)
(the only ones who benefit from a domestication of the human are globohomo)
(and theres rational reasons to celebrate and elevate our combativeness and our resilience against adversity)
>>
(transhumanist thread btw)
(trannors thinking bc theres trans in the word, they can apply please abstain)
(youre the celebration of everything thats vile and base in a human being)
(you are the opposite of transcendence, youre the expression of using technology to attain vile, broken instincts)
>>
>attain
*satisfy
>>
File: .webm (271 KB, 864x480)
271 KB
271 KB WEBM
I made picrel, but kinda ran out of ideas to extend it
I've been looking up how to do shit on Win32 to give it a GUI but I feel finished with it
this is the code: https://pastebin.com/yz8CC9x6
you can't do exactly what's shown, it's very slightly altered to fit a base image
unrelated funny thing, I couldn't go below 6M on gif yet it's less than 300k on vp9
>>
fkn hell anons i wanna talk about C
and actually learn things
why do i have to know what shits about
you realize that when you dont know i have the moral obligation to share stuff taht makes sense
which i kinda dont wanna
bc i come here to talk about c
and make fun of trannors
>>
>>102113409
>-march=native
everyone should use it
>>
(unironically, it enables auto vectorization depending on the instuction set you have available on your cpu. break protability tho. but who cares)
>>
>>102111009
union vector {
__m256d m;
double p[4];
struct { double x, y, z, w; };

vector() = default;

vector(__m256d m) {
this->m = m;
}

vector(const double* p) {
m = _mm256_load_pd(p);
}

vector(double s) {
m = _mm256_set1_pd(s);
}

vector(double x, double y, double z, double w) {
m = _mm256_set_pd(w, z, y, x);
}

double& operator[](int i) {
return p[i];
}

vector operator+(const vector& v) const {
return _mm256_add_pd(m, v.m);
}

vector operator-(const vector& v) const {
return _mm256_sub_pd(m, v.m);
}

vector operator*(double s) const {
return _mm256_mul_pd(m, _mm256_set1_pd(s));
}

vector operator-() const {
return *this * -1.0;
}

vector operator+=(const vector& v) {
return *this = *this + v;
}

vector operator-=(const vector& v) {
return *this = *this - v;
}
};
>>
>>102111884
the default theme color is shit brown? for what reason?
>>
>>102113486
>c++
fuck off
>>
File: 1717498985843201.jpg (55 KB, 1024x560)
55 KB
55 KB JPG
>>102113498
jeets can't help it
>>
>>102113510
>brothers from another mother
you shoudlnt be like that
>>
>>102113498
because it's orange and not brown
>>
>>102113498
>>102114022
amberish, to be more exact
>>
>>102114022
>orange
in what world?
>>102114054
>amberish, to be more exact
a fancier way to spell shit? it's a literal shit color pallet
>>
>>102114054
Then fix your monitor, your eyes or your diet. One of them is definitively fucked up.
And you can changes the colors anyway if you don't like them.
>>
>>102114107
wrong quote meant for >>102114194
>>
>>102114208
fucked up again, fuck me. It's late, you get the point.
>>
>>102106304
C is a high level language that's compiled to a low level language and then binary.
>>
>>102105084
I am currently working on rewriting all the exercises I previously did for C a modern approach because like a dumbass I lost all my previous progress and made excuses not to pick the book back up. I understand the ins and outs of C as it's presented in the book but I am getting filtered by some of the more math heavy ones.
>>
>>102113486
>>102113848
>different use cases
>different paradigms
>different rules and standards
C++ has nothing to do with C
>>
>>102114588
even if that would give you ptsd
i can raw pointers in sepples

even if you disavow with all your might
we ARE brothers
>>
What is the safest way to convert a string an int?
>>
>>102115917
allocate a buffer on the heap
iirc you need 10 digits for the number (for a 32 bit integer)and eventually an 11th char for the null termination
>safest
what a weird question
>>
`strtol` - note it returns zero if conversion fails, and you cannot distinguish this from e.g. "0"
on over/underflow errno is set and the function returns the limit from climits
>>
>>102115917
>>102115993
oops
>>
>>102115917
cstdlib is retarded sometimes.
you have to verify it is a valid int first and then call stol or friends.
it's really not hard to roll this one yourself.
1*first digit + 10*second digit + 100*third digit etc.
if (INT_MAX - old_sum > new_term) then return overflow token
>>
>>102114588
#define WORLD_UP vector(0, 1.0, 0, 0)

union camera {
matrix mat = identity();
struct { vector right, up, dir, pos; };

void turn(const vector& v) {
dir = normalize(v);
right = -cross(dir, WORLD_UP);
right = normalize(right);
up = cross(dir, right);
up = normalize(up);
}

void turn(double dX, double dY) {
dir = rotate(dir, WORLD_UP, dX);
dir = rotate(dir, right, dY);
turn(dir);
}
};
>>
>>102116099
get your c++ ass out of here
>>
File: 1722197820042989.jpg (35 KB, 562x673)
35 KB
35 KB JPG
>>102114588
>>
>>102106304
it's a simple high-level language with a ton of compiler for it and even cpus are optimized for it (e.g. via specex and other microcode JIT compilation), making it an effective high-level language for systems programming and otherwise very diverse applications.
true low-level languages MUST expand with CPU development, stick with limited CPU archs, or depend on libraries a lot.
low-level language means you can be as efficient as assembly without a "smart" compiler.

from what I hear fortran and cobol are closer to actual low-level languages than C. there are very few low-level languages that also support many platforms, which is why C is sometimes called "low-level".

you can do anything in C and with reasonable programmer comfort and 90+% efficiency vs. assembly on platforms which are not virtualized and not highly parallel (C's main weak point, it is serial executioj-oriented), e.g. not Android which requires a JVM, not a LISP-machine which to the best of my knowledge does a bunch of CPU-side JIT, not GPU or ASIC programming.
>>
>>102116218
afaik high-level means abstracted from the instruction set
fortran was in fact the first high-level language
you can then compare high-level languages as higher/lower-level by additional abstraction they provide
so c would be, confusingly, a high-level language, but lower-level than js
>>
>>102115917
I guess that strtol and strtoll are "safe" but they are locale dependent, anyway you must avoid atoi.
>>
>>102116362
yes that's what I meant, that's why I named the three ways of dealing with multiple instruction sets with one language (limit to arch, expand with archs, or modularize)
>fortran
correct I just don't have much personal experience with Fortran so I'm hesitant to categorize it
>lower-level
"less abstract" is clearer, more direct.
maybe we should rather say "concrete vs. abstract programming languages" unless we intend to be speaking abstract English
>>
>>102107817
Installing msys2 and then gcc will give you a compiler and compatibility libraries. Then you can install vc code if you need an IDE, or just use a text editor or nodepad ++
>>
Helpful thread guys!
>>
File: n.png (64 KB, 644x753)
64 KB
64 KB PNG
>>102115917
prevent overflow and avoid division by variable at runtime
>>
>>102118528
there are multiple error branches. use the return code for that.
INT_MAX is a valid int, not an error
>>
>>102118528
does this work for negative values?
>>
>>102109161
>I'm making a very minimalistic gameboy emulator, for fun
me too! the cpu was pretty fun! the apu and ppu are a headache. I wish there was more docs and code to read about the apu stuff. the pandocs are so barebones and not that many emulators implement sound!

https://gbdev.io/pandocs/Audio_details.html
>>
god bless this thread
>>
>>102115917
>>102115981
>>102116087
>>102118528
This is Ctranny brain damage and Worse is Better. A lot of computers have instructions to convert between binary and decimal. If you use Ctranny code like this, you won't be able to use them.
>>
>>102120320
Who's Ktranny?
>>
>>102120320
>instructions to convert between binary and decimal
what? point one out
>>
this kills the reimplementing tranny
>>
>>102110915
where does a quad compile then? as far as I know, GPU doesn't render quads so it won't compile even on vulkan or directx.
The quad I'm talking about is just two triangles drawn with GL_TRIANGLE_STRIP or GL_TRIANGLE in opengl.
>>
My life was changed...
> somehow crashed all instances of Xfce4 terminal emulator (had 6 terminals opened) with few dozen 'ls' commands...
> rage-quitted, watched one physics documentary, dd-ed ROSA GNU/Linux onto USB, installed in, looks beautiful...
> got PTSD flashbacks of KDE Plasma slowness, 1.6 GiB of RAM on idle, DNF suckiness, Mandriva experience (tm)...
> decided to dd BunsenLabs Boron (k 6.10.0) onto USB, instead of my ancient Helium (k 4.19.0), installed...
--
I ditched ancient software, most of my programs until yesterday were binary packages from 2016, in old-old-old-stable repositories.
My kernel was 4.19.0, gcc 8.3.0, now using something more up to date...
>>
>>102121659
Oh my gooood, like touch grass.
>>
>>102120320
what?
>>
>>102122277
I guess...
>>
>>102123350
Like, oh em geee...
>>
>>102123398
This is even better, 420 allocations...
>>
>>102123944
What a retard.
>>
Rude.
>>
bump();
>>
trying to do a neural network, but i am dumb af
>>
>>102125823
It's just linear albegra, you don't even need differentials in order to make a simple one...
I hate recommending streams, but Tsoding, Russian twink who writes bad C, explained it well.
Since he implemented neural network in C, you can easily watch it, and rewrite it in any language.
>>
>>102105282
Win32 API /thread
>>
File: file.png (195 KB, 396x462)
195 KB
195 KB PNG
>>102126094
noted. thank you anon
>>
>>102126094
What's bad about his C?
>>
>>102126792
You're welcome.
>>102126811
> What's bad about his C?
Nothing to be honest, I'm retarded Adafag who's too pedantic for his own good, and even tho I'm aware of that, I persist with my egoistical crap...
--
I prefer to use 90% of Ada Coding Standard rules (aka Style Guide) in my code, in any language. He writes Linux Guide style C, which I dislike...
--
One objectively serious note on his C code is that he doesn't clean up, his code leaves a lot of Valgrind warnings. Invalid IO, memory leaks, etc.



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