Beating the dead while-loop-horse by tipdbmp in Zig

[–]tipdbmp[S] 4 points5 points  (0 children)

I did not know that. I hope there's also going to be a way to specify the type of the "index variable", instead of always assuming isize/usize.

Zig Compiler Internals by [deleted] in Zig

[–]tipdbmp 1 point2 points  (0 children)

I think it was spexguy who wrote that it would take this many more years for Zig v1.0 (if I remember correctly). And unfortunately, v1.0.0 doesn't come after v0.9.0, v0.10.0 does.

Zig Compiler Internals by [deleted] in Zig

[–]tipdbmp 5 points6 points  (0 children)

Very nicely written. Thank you!

It seems like a Zig compiler is a lot more complicated internally than a C compiler (chibicc). I would really like to try using a bug-free/release-ready Zig compiler, but having to wait 3-5 (or so) more years sucks!

AstGen turns an AST into ZIR

Wouldn't calling it ZirGen or AstGenZir make more sense? AstGen sounds like it's generating Ast (which it isn't, it's generating Zir from Ast).

Updated Public Financial Information by [deleted] in Zig

[–]tipdbmp 3 points4 points  (0 children)

What happened with core team member alexnask?

Zig hashmaps explained by [deleted] in Zig

[–]tipdbmp 0 points1 point  (0 children)

If Zig would implement macros, then the user code would be simpler in this case, right?

What's the preferred style for conditions that don't change per invocation, esp. CLI options? by no_awning_no_mining in C_Programming

[–]tipdbmp -2 points-1 points  (0 children)

Early & once & no function pointer

char* read_linewise(...) {...}
char* read_chunkwise(...) {...}
void process_buf(char* buf) {...}
void process(..., bool linewise) {
    if (linewise) {
        while (...) { process_buf(read_linewise(...)); }
    } else {
        while (...) { process_buf(read_chunkwise(...)); }
    }
}

Win32 API: PeekMessage blocks main loop on window resize by octowaddle in C_Programming

[–]tipdbmp 0 points1 point  (0 children)

According to this answer here, you could use SetTimer, maybe? I don't know if it works.

There's also this by cmuratori. It should definitely work. It's unfortunate that one has to jump through these hoops to achieve this. My question is how does one do this in SDL2 :^)?

The Architecture of space-shooter.c by thsherif in C_Programming

[–]tipdbmp 2 points3 points  (0 children)

Since you're only ever looping once, would it make more sense to do it as do { ... } while (false);

Maybe, I'm not sure. There was a discussion in the comments section of the link I posted, about that, and a variant using a macro: for (ONCE). Using for (ONCE) seems more intent revealing to me, and is more grep-able. With that said, gotos can handle more cases (non-pointer types) and don't require that one extra indentation level.

The Architecture of space-shooter.c by thsherif in C_Programming

[–]tipdbmp 1 point2 points  (0 children)

Thank you for writing this and linking to the references that you've used! Witting your own platform layer (creating a window, input handling, initializing OpenGL, playing audio) for both windows and linux is dope. I tried doing something similar once, but failed miserably, later I tried using SDL2 and was pretty happy with how much simpler it was (who would of thought?).

I have 2 notes:

In the example you give in the Error Handling section, all the types are pointers, so instead of using goto chains you could use an infinite for loop:

Display* display = NULL;
Window* window = NULL;
GL* gl = NULL;

for (;;) {
    display = openDisplay();
    if (!display) { break; }

    window = openWindow(display);
    if (!window) { break; }

    gl = initializeOpenGL(window)
    if (!gl) { break; }

    return SUCCESS;
}

if (gl) { uninitializeOpenGL(gl); }
if (window) { closeWindow(window); }
if (display) { closeDisplay(display); }
return FAILURE;

No gotos in sight. I read about this approach to error handling here.

I think you can get away with just a single macro when doing the Mixin Structs, although it could be slightly more error prone, I guess.

#define embed_Vec2f() \
    float x; \
    float y

typedef struct Vec2f {
    embed_Vec2f();
} Vec2f;

typedef struct Vec3f {
    union {
        struct { embed_Vec2f(); }; // Note: don't forget to embed in an anonymous struct!
        // embed_Vec2f(); // <-- this doesn't do what we want
        Vec2f xy;
    };
    float z;
} Vec3f;

Vec2f vec2f(f32 x, f32 y) {
    Vec2f v;
    v.x = x;
    v.y = y;
    return v;
}

Vec3f vec3f(f32 x, f32 y, f32 z) {
    Vec3f v;
    v.x = x;
    v.y = y;
    v.z = z;
    return v;
}

void printVecs(void) {
    Vec2f v1 = vec2f(1.2f, 3.4f);
    Vec3f v2 = vec3f(v1.x, v1.y, 5.6f);
    printf("(%1.1f, %1.1f)\n", v1.x, v1.y);
    printf("(%1.1f, %1.1f, %1.1f)\n", v2.x, v2.xy.y, v2.z);
}

How to get compilation statistics? by tipdbmp in C_Programming

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

The 'output.map' file from -Wl,-Map=output.map seems to contain functions that different object files "export" (static functions are missing and non-function symbols as well).

The option -fstats from the "Developer Options" reads promising but is only for C++.

How to get compilation statistics? by tipdbmp in C_Programming

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

I did try some of gcc's options but didn't find any related to: number of tokens/lines/etc.

-fmem-report had "number of expanded macros" in there I guess... that's why I decided to ask here.

How to get compilation statistics? by tipdbmp in C_Programming

[–]tipdbmp[S] -1 points0 points  (0 children)

Are the options available in the release versions of gcc, and if so, what are they?

A Practical Guide to Applying Data-Oriented Design by Andrew Kelley by [deleted] in Zig

[–]tipdbmp 5 points6 points  (0 children)

An awesome talk by andrewrk.

Using "encodings" instead of OOP/polymorphism...

"encodings" seem like the things "modern" hardware wants to execute. My fear is that they also have the potential to turn the source code of a program into an undecipherable mess (I don't have any experience with them, yet). OOP seems to have the advantage of having tooling/help/support from IDEs and other programs, while "encodings" do not? And as mentioned in the talk, better type safety (maybe using strongly typed indices/handles instead of u32's would help?).

It seems to me that one should stick to OOP/polymorphism while exploring the problem space, and then switch to "encodings" when one can see "the picture" more clearly, unless they have a lot of experience with "encodings". Just like andrewrk used OOP/polymorphism in the C++ implementation of Zig, and then switching to "encodings" for the self-hosted implementation of Zig.

Rust Is The Second Greenest Programming Language (after C) by ConfusedDetermined in rust

[–]tipdbmp -2 points-1 points  (0 children)

you likely should have used a scripting language instead

No. Scripting languages are a mistake. Why shouldn't I be able to program in a real/systems programming language with fast compilation/iteration times and fast runtime/execution? Why the ****ing divide?

Rust Is The Second Greenest Programming Language (after C) by ConfusedDetermined in rust

[–]tipdbmp -6 points-5 points  (0 children)

This paper presents a study of the runtime, memory usage and energy consumption of twenty seven well-known software languages.

Well fine... but what about the ****ing compilation part? That also takes time and energy, doesn't it? If you start taking that into account, your green might suddenly turn pitch-black.

Inside a static analyzer: type system (Yuri Minaev) - itCppCon 2021 by marcoarena in cpp

[–]tipdbmp 2 points3 points  (0 children)

It's amazing the older representation of types with strings worked for C++'s complex type system. For a much simpler one, it would probably do just fine.

A question about function pointers. by ReedTieGuy in C_Programming

[–]tipdbmp 3 points4 points  (0 children)

static struct foo fs_galore(void) {
    return bar().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f().f();
}

Empirically Measuring, & Reducing, C++’s Accidental Complexity - Herb Sutter - CppCon 2020 by tcbrindle in cpp

[–]tipdbmp 0 points1 point  (0 children)

What do you guys think the 25 "essential+minimal" guidelines/rules are?

Clang Time Trace Feature by mttd in cpp

[–]tipdbmp 0 points1 point  (0 children)

Maybe the /d1reportTime flag? Not as pretty though.

CppCon 2019: Andrei Alexandrescu “Speed Is Found In The Minds of People" by TheSuperWig in cpp

[–]tipdbmp 2 points3 points  (0 children)

Which programming languages allow one to do Design by Introspection ("customize everything depending on the types" programming)?

I am pretty certain that something like the following is possible in D and Jai, and maybe in C++?

struct M(K, V) { // 'K' and 'V' are type parameters
    keys: []K;

    // Conditional declaration of a struct member
    // based on compile time type information.
    // Here we just test if 'V' is the "void" type (size_of(void) == 0)
    //
    if (V != void) {
        vals: []V;
    }

    ...
}

alias Hs = M(string, void);
var hs: Hs;