Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
netcat
Apr 29, 2008

chglcu posted:

FTFY

After using it for game development for over 20 years, I've recently taken a hard hard turn into being sick of its bullshit.

Lol same (except I don’t work in gamedev). I used to kinda like C++ but it just makes me tired these days.

I’ve started poking a bit at rust which I’ve been very suspicious of but it does seem kinda nice... So far just IDE integration feels a million times nicer than for C++. And dependency handling with cargo is really nice but I expect some bullshit if you pull in something that depends on a C/C++ library

Adbot
ADBOT LOVES YOU

chglcu
May 17, 2007

I'm so bored with the USA.
I read the rust book and I was super excited about it until I actually tried writing real code in it and I just felt like I was fighting the language. I probably need to give it another shot, but in the short time I spent with it, libraries seemed very immature and poorly documented. That, and I threw up in my mouth a little bit every time I saw the word 'rustacean'.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I wish I had a better alternative to C++, but that's not happening any time soon. Everything I do is either legacy code where we're just stuck with what we've got, or writing an R package where no other reasonably performant language is really supported.

ultrafilter fucked around with this message at 18:06 on Mar 5, 2021

duck monster
Dec 15, 2004

chglcu posted:

FTFY

After using it for game development for over 20 years, I've recently taken a hard hard turn into being sick of its bullshit. Just sucks that the alternatives seem to be even worse for that particular niche.

loving Pascal under Borland had the potential to be the less bullshit fillled alternative to C++, for a while its Turbo Pascal compilers produced code that ran neck and neck as fast as C++ without the giant cognitive load required not to gently caress it up in C++, but that company got taken over by insane enterprise suits more interested in peddling lovely enterprise CORBA style shovelware and pricing its toolchains far beyond amy hobbyists means and let Pascal die on the vine of history. Shame, back in the 90s Turbo Pascal and Delphi where absolute delights to use

cheetah7071
Oct 20, 2010

honk honk
College Slice
I will say that switching from R and Python, it was very liberating to just be able to write my own loops instead of looking for a pre-written function backed by C++ code which does my loop for me. (And not have it take forever to loop over a hundred million data points)

Volguus
Mar 3, 2009

duck monster posted:

loving Pascal under Borland had the potential to be the less bullshit fillled alternative to C++, for a while its Turbo Pascal compilers produced code that ran neck and neck as fast as C++ without the giant cognitive load required not to gently caress it up in C++, but that company got taken over by insane enterprise suits more interested in peddling lovely enterprise CORBA style shovelware and pricing its toolchains far beyond amy hobbyists means and let Pascal die on the vine of history. Shame, back in the 90s Turbo Pascal and Delphi where absolute delights to use

I always hated begin and end and typing := (although it's easier and clearer to read).

Insurrectum
Nov 1, 2005

cheetah7071 posted:

I will say that switching from R and Python, it was very liberating to just be able to write my own loops instead of looking for a pre-written function backed by C++ code which does my loop for me. (And not have it take forever to loop over a hundred million data points)

Everything's fun and peachy in a compiled language until you have to touch a string

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Insurrectum posted:

Everything's fun and peachy in a compiled language until you have to touch a string

Also, yeah, not having to worry about the performance of a loop is great. But having to write loops every time I want to loop over something is extremely tiring. My biggest complaint about C++ is that it forces me to spend a lot of time thinking about things that I don't care about. That's gotten better with the modern standard library but it's still not all the way there yet.

Presto
Nov 22, 2002

Keep calm and Harry on.

Volguus posted:

I always hated begin and end and typing := (although it's easier and clearer to read).
Never look at the source for the original Bourne shell.

Computer viking
May 30, 2011
Now with less breakage.

Remember, the only thing between you and
code:
#define begin {
#define end }
is a feeling of moral responsibility to something greater than yourself.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


code:
#define { }
#define } {

pseudorandom name
May 6, 2007

code:
sa.c:1:9: error: macro name must be an identifier
#define { }
        ^
sa.c:2:9: error: macro name must be an identifier
#define } {
        ^
2 errors generated.

Raenir Salazar
Nov 5, 2010

College Slice
This is perhaps a silly question but is there a convenient term for referring to objects allocated on the stack (without using 'new') and objects allocated on the heap (using 'new')?

Or is it "RAII Objects vs Instantiated Objects" or something?

Jeffrey of YOSPOS
Dec 22, 2005

GET LOSE, YOU CAN'T COMPARE WITH MY POWERS
It's kinda weird and a blurry line in C++ because objects can call new themselves - a vector has its elements in the heap even if the vector itself is stack-allocated. I would call them stack-allocated and heap- or dynamically allocated.

Raenir Salazar
Nov 5, 2010

College Slice

Jeffrey of YOSPOS posted:

It's kinda weird and a blurry line in C++ because objects can call new themselves - a vector has its elements in the heap even if the vector itself is stack-allocated. I would call them stack-allocated and heap- or dynamically allocated.

What if I want to avoid confusion when I am also discussing using a heap data structure (std::make_heap etc)? :)

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Just enforce a rule that heaps are always stack-allocated and stacks are always heap-allocated. You'll never be confused again.

Xarn
Jun 26, 2015
Automatic vs dynamic storage

hbag
Feb 13, 2021

alright, if im on linux, writing a program for windows and using mingw to compile it, how would i go about specifying the application entry point to be WinMain? When I try compiling it normally, it whines about a few things not being defined (they are defined later in the code, but called in the code before WinMain, which leads me to believe it's just trying to go from top to bottom rather than starting at WinMain)

To be specific, here's the code I'm trying to compile - I'm just using the example from the Windows API documentation to get poo poo working (so I don't just assume everything is my own bad code):

code:
#include <windows.h> 
 
// Global variable 
 
HINSTANCE hinst; 
 
// Function prototypes. 
 
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int); 
InitApplication(HINSTANCE); 
InitInstance(HINSTANCE, int); 
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); 
 
// Application entry point. 
 
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow) 
{ 
    MSG msg; 
 
    if (!InitApplication(hinstance)) 
        return FALSE; 
 
    if (!InitInstance(hinstance, nCmdShow)) 
        return FALSE; 
 
    BOOL fGotMessage;
    while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1) 
    { 
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    } 
    return msg.wParam; 
        UNREFERENCED_PARAMETER(lpCmdLine); 
} 
 
BOOL InitApplication(HINSTANCE hinstance) 
{ 
    WNDCLASSEX wcx; 
 
    // Fill in the window class structure with parameters 
    // that describe the main window. 
 
    wcx.cbSize = sizeof(wcx);          // size of structure 
    wcx.style = CS_HREDRAW | 
        CS_VREDRAW;                    // redraw if size changes 
    wcx.lpfnWndProc = MainWndProc;     // points to window procedure 
    wcx.cbClsExtra = 0;                // no extra class memory 
    wcx.cbWndExtra = 0;                // no extra window memory 
    wcx.hInstance = hinstance;         // handle to instance 
    wcx.hIcon = LoadIcon(NULL, 
        IDI_APPLICATION);              // predefined app. icon 
    wcx.hCursor = LoadCursor(NULL, 
        IDC_ARROW);                    // predefined arrow 
    wcx.hbrBackground = GetStockObject( 
        WHITE_BRUSH);                  // white background brush 
    wcx.lpszMenuName =  "MainMenu";    // name of menu resource 
    wcx.lpszClassName = "MainWClass";  // name of window class 
    wcx.hIconSm = LoadImage(hinstance, // small class icon 
        MAKEINTRESOURCE(5),
        IMAGE_ICON, 
        GetSystemMetrics(SM_CXSMICON), 
        GetSystemMetrics(SM_CYSMICON), 
        LR_DEFAULTCOLOR); 
 
    // Register the window class. 
 
    return RegisterClassEx(&wcx); 
} 
 
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow) 
{ 
    HWND hwnd; 
 
    // Save the application-instance handle. 
 
    hinst = hinstance; 
 
    // Create the main window. 
 
    hwnd = CreateWindow( 
        "MainWClass",        // name of window class 
        "Sample",            // title-bar string 
        WS_OVERLAPPEDWINDOW, // top-level window 
        CW_USEDEFAULT,       // default horizontal position 
        CW_USEDEFAULT,       // default vertical position 
        CW_USEDEFAULT,       // default width 
        CW_USEDEFAULT,       // default height 
        (HWND) NULL,         // no owner window 
        (HMENU) NULL,        // use class menu 
        hinstance,           // handle to application instance 
        (LPVOID) NULL);      // no window-creation data 
 
    if (!hwnd) 
        return FALSE; 
 
    // Show the window and send a WM_PAINT message to the window 
    // procedure. 
 
    ShowWindow(hwnd, nCmdShow); 
    UpdateWindow(hwnd); 
    return TRUE; 
 
}

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

hbag posted:

alright, if im on linux, writing a program for windows and using mingw to compile it, how would i go about specifying the application entry point to be WinMain? When I try compiling it normally, it whines about a few things not being defined (they are defined later in the code, but called in the code before WinMain, which leads me to believe it's just trying to go from top to bottom rather than starting at WinMain)

code:
InitInstance(HINSTANCE, int); 
[...]
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow) 
{ ... }
Prototype/declarations should match the instantiations. Compilation goes from top to bottom, the execution entry point is a completely different thing which it doesn't sound like is your problem.

hbag
Feb 13, 2021

roomforthetuna posted:

Prototype/declarations should match the instantiations. Compilation goes from top to bottom, the execution entry point is a completely different thing which it doesn't sound like is your problem.

...So it's a case of the documentation being wrong?
https://docs.microsoft.com/en-us/windows/win32/winmsg/using-window-classes

Thanks, Microsoft.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
BOOL is a typedef for int and C functions have a default return type of int so that's a valid declaration.

chglcu
May 17, 2007

I'm so bored with the USA.
Are you specifying to use the windows subsystem? Without that, I think it’ll create a console executable which would use main as the entry point instead of WinMain. Without seeing your actual error output, it’s hard to say if that’s related. Not sure what the switch for mingw would be.

hbag
Feb 13, 2021

chglcu posted:

Are you specifying to use the windows subsystem? Without that, I think it’ll create a console executable which would use main as the entry point instead of WinMain. Without seeing your actual error output, it’s hard to say if that’s related. Not sure what the switch for mingw would be.

yep. i tried this: i686-w64-mingw32-gcc file.cpp -Wl,-subsystem,windows - and what i got was an error whining about InitApplication and InitInstance not being defined

chglcu
May 17, 2007

I'm so bored with the USA.

hbag posted:

yep. i tried this: i686-w64-mingw32-gcc file.cpp -Wl,-subsystem,windows - and what i got was an error whining about InitApplication and InitInstance not being defined

With it being a .cpp file, it could be being compiled as c++ and the default int return type thing doesn’t apply there, as far as I know, so the mismatched prototypes causing a problem could make sense.

hbag
Feb 13, 2021

chglcu posted:

With it being a .cpp file, it could be being compiled as c++ and the default int return type thing doesn’t apply there, as far as I know, so the mismatched prototypes causing a problem could make sense.

really? i thought the windows API was only C++, not C
guess i'll try compiling it as C and see what happens

chglcu
May 17, 2007

I'm so bored with the USA.

hbag posted:

really? i thought the windows API was only C++, not C
guess i'll try compiling it as C and see what happens

Win32 is actually a C API (C89 with some MS extensions, I believe), though it can be used from C++. Some other windows libraries use C++, but the core API is C.

hbag
Feb 13, 2021

chglcu posted:

Win32 is actually a C API (C89 with some MS extensions, I believe), though it can be used from C++. Some other windows libraries use C++, but the core API is C.

ah, right, thanks - im not on my laptop (that the code is on) right now but i'll give it a try when i get on it in an hour or so

hbag
Feb 13, 2021


getting closer i think

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

hbag posted:

...So it's a case of the documentation being wrong?
https://docs.microsoft.com/en-us/windows/win32/winmsg/using-window-classes

Thanks, Microsoft.
Yeah, even if the "default return type in C is int" thing holds true, the fact that BOOL is typedeffed as int is an implementation detail that's supposed to have been made irrelevant by the typedef (it should be possible to change the underlying type of BOOL and have all correctly written code still compile and work), so though it will compile in a C compiler it is still incorrect of them to write it that way. And also, if you're going to rely on the default int return type you really ought to be doing it in the declaration *and* the implementation for consistency, so that documentation is crappy for two reasons, though technically "it will work".

Your new error looks familiar, I think you get that from not doing int WINAPI WinMain.

hbag
Feb 13, 2021

roomforthetuna posted:

Yeah, even if the "default return type in C is int" thing holds true, the fact that BOOL is typedeffed as int is an implementation detail that's supposed to have been made irrelevant by the typedef (it should be possible to change the underlying type of BOOL and have all correctly written code still compile and work), so though it will compile in a C compiler it is still incorrect of them to write it that way. And also, if you're going to rely on the default int return type you really ought to be doing it in the declaration *and* the implementation for consistency, so that documentation is crappy for two reasons, though technically "it will work".

Your new error looks familiar, I think you get that from not doing int WINAPI WinMain.

Aaaand now I'm getting this:
[whoops nevermind that was a typo on my part]

hbag fucked around with this message at 11:55 on Mar 8, 2021

hbag
Feb 13, 2021

the ACTUAL new error seems to be this:

more falafel please
Feb 26, 2005

forums poster

hbag posted:

the ACTUAL new error seems to be this:


It looks like it thinks your calls to InitApplication() and InitInstance() are actually declarations of variables, and it's complaining that you didn't specify what their type is. Likely you need a declaration of those functions above the point where they're called.

e: ah, you're declaring them near the top, but not specifying their return type.

nielsm
Jun 1, 2009



hbag posted:

the ACTUAL new error seems to be this:


Two things in those linker errors:

You are missing the MainWndProc function entirely, you need to a window procedure for the program to work.
Additionally, it looks like you're missing one or more system libraries for linking, since it's complaining about _imp__GetStockObject@4 (that's a GDI function). Make sure you're linking both the KERNEL32, USER, and GDI libraries.

You really should fix the prototypes of your InitApplication() and InitInstance() functions to include the return type BOOL, if nothing else to make good habits.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

hbag posted:

the ACTUAL new error seems to be this:

So now that you're getting "undefined reference to MainWndProc", which is now a link-time error, it's something closer to the libraries or toolchain.

Generally when you run into errors at that level Google+StackOverflow will be your friend. I just searched for "undefined reference to MainWndProc" and the top result was about building a Windows target with mingw, encountering that error, and had an answer, so it might be exactly the answer you need.

pseudorandom name
May 6, 2007

roomforthetuna posted:

So now that you're getting "undefined reference to MainWndProc", which is now a link-time error, it's something closer to the libraries or toolchain.

Generally when you run into errors at that level Google+StackOverflow will be your friend. I just searched for "undefined reference to MainWndProc" and the top result was about building a Windows target with mingw, encountering that error, and had an answer, so it might be exactly the answer you need.

It isn't, MainWndProc is a user implemented callback, not an OS supplied function.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

pseudorandom name posted:

It isn't, MainWndProc is a user implemented callback, not an OS supplied function.
Oh, duh, so it is. Declared next to those other bad declarations, used in InitApplication, and never actually defined.

Nalin
Sep 29, 2007

Hair Elf
Does anybody know how C++20's iterator concepts work? I've been trying to find information on how to construct a custom iterator for C++20's concepts, but I just haven't been able to find anything online describing the changes.

Is it some new style of designing your iterator class, or is it just an enhancement on top of the current method of tagging your iterator_category and providing your standard difference_type, value_type, etc, properties? Or is it just too early to think about this because no STL implementation has bothered with it yet?

giogadi
Oct 27, 2009

I seem to recall some random trivia that, if you want to represent a 3D Vector as a struct, it can be advantageous to actually store 4 values:

code:
struct Vector3d {
    float x, y, z, unused;
};
Has anyone else heard this? My only guess here is that this helps guarantee that your vectors will fit neatly in a 32B cache line (because a 12-byte vector would not evenly divide 32B). This means that each vector access would require only 1 cache read. But there's a tradeoff here, right? It seems like you can't store as many vectors in the cache if each one is bigger.

What do y'all think?

cheetah7071
Oct 20, 2010

honk honk
College Slice

giogadi posted:

I seem to recall some random trivia that, if you want to represent a 3D Vector as a struct, it can be advantageous to actually store 4 values:

code:
struct Vector3d {
    float x, y, z, unused;
};
Has anyone else heard this? My only guess here is that this helps guarantee that your vectors will fit neatly in a 32B cache line (because a 12-byte vector would not evenly divide 32B). This means that each vector access would require only 1 cache read. But there's a tradeoff here, right? It seems like you can't store as many vectors in the cache if each one is bigger.

What do y'all think?

Are you sure this isn't because of quaternion math? Rotating vectors is really easy when the number of dimensions is a power of two, so the usual way it's handled is to pretend your vector is four-dimensional, rotate it, and then go back to ignoring the fourth dimension. It's used all the time in computer graphics.

Adbot
ADBOT LOVES YOU

giogadi
Oct 27, 2009

cheetah7071 posted:

Are you sure this isn't because of quaternion math? Rotating vectors is really easy when the number of dimensions is a power of two, so the usual way it's handled is to pretend your vector is four-dimensional, rotate it, and then go back to ignoring the fourth dimension. It's used all the time in computer graphics.

I’m not sure - I always thought the fastest way to rotate a 3d vector is just to multiply with a 3x3 rotation matrix. Like, you can directly rotate a vector with a quaternion but it’s about as fast as converting the quat into a rotation matrix and just rotating that way. But I might be wrong!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply