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
feedmegin
Jul 30, 2008

Twerk from Home posted:

I'm excited about the idea of a "linux from 2003" docker image, but also concerned because these things now need more than 4GB of RAM because of how much bigger DNA chips have gotten since then and I'm worried that 64-bit linux stability was not good until some time after that.

64-bit Linux has been a thing since the DEC Alpha port in the mid 90s. This isnt Windows we're talking about here.

Adbot
ADBOT LOVES YOU

Doc Block
Apr 15, 2003
Fun Shoe
I’m sorry Microsoft, but no matter what the nag warnings you’ve added to the latest version of Visual Studio 2019 say, I cannot change vulkan.h to use enum class instead of enum :rolleyes:

“VkResult is unscoped. Prefer ‘enum class’ over ‘enum’” etc etc etc x1000

Xerophyte
Mar 17, 2008

This space intentionally left blank
VS has a mechanism that lets you define external headers according to some criteria and set a different warning level for these. See blogpost for excessive detail, short version is

Le Microsoft posted:

We offer a new compiler switch group: /external:* dealing with “external” headers. We chose the notion of “external header” over “system header” that other compilers use as it better represents the variety of 3rd party libraries in existence. Besides, the standard already refers to external headers in [lex.header], so it was only natural. We define a group instead of just new switches to ease discoverability by users, which would be able to guess the full syntax of the switch based on the switches they already know. For now, this group consists of 5 switches split into 2 categories (each described in its own section below):

Switches defining the set of external headers
  • /external:I <path>
  • /external:anglebrackets
  • /external:env:<var>
Switches defining diagnostics behavior on external headers
  • /external:W<n>
  • /external:templates-
The 2nd group may later be extended to /external:w, /external:Wall, /external:Wv:<version>, /external:WX[-], /external:w<n><warning>, /external:wd<warning>, /external:we<warning>, /external:wo<warning> etc. which would constitute an equivalent of the corresponding warning switch when applied to an external (as opposed to user) header or any other switch when it would make sense to specialize it for external headers. Please note that since this is an experimental feature, you will have to additionally use /experimental:external switch to enable the feature until we finalize its functionality. Let’s see what those switches do.

That was in 2017, I don't know if /experimental:external is still required. I've never used this, we manually push/pop warning levels around "bad" header includes at work. Consequences of include being a fancy copy-paste function, really.

Doc Block
Apr 15, 2003
Fun Shoe
I’ve already done the push/pop warnings around the includes thing, but the warning still randomly comes back.

Like, I’ll have some code that’s like “VkResult result = vkDoSomething();” and VS will complain about VkResult not being enum class for that line.

Doing it around the whole source file makes the warning permanently go away, but that’s not really ideal, even though in this case it’s harmless.

Xerophyte
Mar 17, 2008

This space intentionally left blank
Huh. That shouldn't happen. Is it possible VkResult is first encountered as a transitive include from some other header, internal or external, that's outside of your push/pop pragma? Is vkDoSomething() a macro?

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

rjmccall posted:

I assume Xarn went to the committee meeting and discovered that they’re somehow even more dysfunctional in person.

Standards, like laws and sausage, are things that you’re better off not knowing how they are made.

Doc Block
Apr 15, 2003
Fun Shoe

Xerophyte posted:

Huh. That shouldn't happen. Is it possible VkResult is first encountered as a transitive include from some other header, internal or external, that's outside of your push/pop pragma? Is vkDoSomething() a macro?

I won’t be at home to look at my PC until this afternoon, but I don’t think so. Typically, vulkan.h needs to be included before any other headers related to Vulkan:

Beef
Jul 26, 2004

Zopotantor posted:

Standards, like laws and sausage, are things that you’re better off not knowing how they are made.

And not unlike spectacular crashes, where you cannot help but stare and wonder what series of unfortunate events led to that point.

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
Since the OP is outdated by over 10 years: What are some good resources to learn C++ nowadays?

I'm looking at some junior-level jobs that require some knowledge of C++, but the only C++ code I've ever written was during my Master's thesis project and I feel like I don't know anything about the language. I picked up the other programming languages I know mostly by just working with them, but somehow that seems to be much harder with C++.

qsvui
Aug 23, 2003
some crazy thing
I've heard that Tour of C++ should get you up to speed on the latest language features.

Core Guidelines may also be helpful.

qsvui fucked around with this message at 05:16 on Feb 18, 2020

Eezee
Apr 3, 2011

My double chin turned out to be a huge cyst
Tour of C++ is exactly what I was looking for. Thank you.

netcat
Apr 29, 2008
Does anyone know of good container/algorithm library that implements something similar to Java streams or the C# equivalent (I want to say LINQ but iirc that's a DSL kindof?)

qsvui
Aug 23, 2003
some crazy thing
Never used Java but if by C# LINQ you mean some functional/declarative way of manipulating sequences, then I guess range-v3 sounds the closest

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Is there a modern and correct way to add a library to my Visual Studio 2019 project?

I'm interested in using fmt https://github.com/fmtlib/fmt

In the past I've had to: clone the source, completely re-learn how to run the CMake gui and run it, point it at the folder, generate the Visual Studio project files (if it fails for any reason then I'm just SOL), then open the visual studio projects and try to build (again, if it fails.. I just give up) and then edit about half a dozen settings in my project to link the libarary.

Is there an easier way?

Xarn
Jun 26, 2015
Yes, write your CMakeLists.txt properly :v:

Volguus
Mar 3, 2009
Checkout vcpkg, it's amazing. I rarely use windows, but when I had to port something to it, vcpkg was a life saver. Then yes, write your cmake properly , don't forget to account for the little VS,/cmake/windows idiosyncrasies, and if you have any hair left after all of this, your project will compile buttery smooth.

Xerophyte
Mar 17, 2008

This space intentionally left blank
There's little they can do to make cmake and some 3rd party library's usage thereof friendlier. Also I'm pretty sure no one has ever written a CMakeLists.txt properly, cmake seems almost purposefully designed to provide so many equally shite ways of doing something that the officially recommended one doesn't stand out.

Anyhow, options:


1) Embrace cmake and all it stands for. This wont make building fmt any easier, but it may make linking it simpler since there are cmake modules for fmt floating around. This one seems mostly sane from a quick scan, but the windows section might need some tweaking.

To use it you'd set CMAKE_MODULE_PATH for your project to point to wherever you keep FindFmt.cmake and other module files for the project, then write
code:
find_package(Fmt REQUIRED)
target_link_libraries(GoonyProject PRIVATE Fmt::Fmt)
and cmake will just generate GoonyProject.vcxproj with the required linking to fmt, plus includes, defines and whatever else the library needs.

2) Shun cmake and all it stands for. fmt is, far as I can tell, two source files and a half dozen headers. Just grab that source for whatever release you want and build it as part of your VS solution, as a normal VS library project. Or as a cmake library if you prefer that, but it doesn't sound like it.


I've never tried one of the VS package management solutions. My immediate reaction is mild skepticism since MSVC can be pretty particular about things like library type flags and debug info format for static linking but maybe they work great, damned if I know.

Personally I'd always include something that tiny as source rather than set up any sort of binary external, but possibly I have been drinking the cool-aid.

qsvui
Aug 23, 2003
some crazy thing

baby puzzle posted:

Is there a modern and correct way to add a library to my Visual Studio 2019 project?

I'm interested in using fmt https://github.com/fmtlib/fmt

In the past I've had to: clone the source, completely re-learn how to run the CMake gui and run it, point it at the folder, generate the Visual Studio project files (if it fails for any reason then I'm just SOL), then open the visual studio projects and try to build (again, if it fails.. I just give up) and then edit about half a dozen settings in my project to link the libarary.

Is there an easier way?

VS 2019 has integrated support for CMake so you can just open your folder that has the root CMakeLists.txt. This link should explain more: https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019

Xarn
Jun 26, 2015
The simplest thing to do is to add a submodule ref to fmtlib/fmt at whichever commit you like, then add_subdirectory the dir where you keep it, and then just target_link_libraries(MyProject PRIVATE fmt::fmt) (or PUBLIC if you export your own headers that mention fmt...).

This will work because it provides an aliased target, see https://github.com/fmtlib/fmt/blob/bed134a4aad3de93b2ba0e1a59a51b662243b7e8/CMakeLists.txt#L166

qsvui
Aug 23, 2003
some crazy thing
If you don't wanna use submodules, then you can get CMake to grab projects using FetchContent

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
nvm i'm not into this today

baby puzzle fucked around with this message at 16:22 on Mar 5, 2020

bolind
Jun 19, 2005



Pillbug
Just stumbled upon this function in a repo and I'm utterly befuddled:

code:
void wtfunction(int status) {
    (void)status;
    *((unsigned volatile int *)0) = 0xDEAD;
}
It's some sort of wrapper function for some exit function in a library, the comments claim...

The (void)status; is probably to satisfy some sort of "you're not using the argument, dummy", but the last line...

pseudorandom name
May 6, 2007

bolind posted:

Just stumbled upon this function in a repo and I'm utterly befuddled:

code:
void wtfunction(int status) {
    (void)status;
    *((unsigned volatile int *)0) = 0xDEAD;
}
It's some sort of wrapper function for some exit function in a library, the comments claim...

The (void)status; is probably to satisfy some sort of "you're not using the argument, dummy", but the last line...
... crashes the program.

Xerophyte
Mar 17, 2008

This space intentionally left blank

pseudorandom name posted:

... crashes the program.

Seems to be taken from one of the shittier answers to the stackoverflow question "what is the easiest way to make a C++ program crash?". It's an approach used in popular applications. Unfortunately.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.

Xerophyte posted:

Seems to be taken from one of the shittier answers to the stackoverflow question "what is the easiest way to make a C++ program crash?". It's an approach used in popular applications. Unfortunately.

I use it to test my crash handlers because abort() doesn't work for that.

Which solution isn't lovely?

Xarn
Jun 26, 2015
Does raise(SIGSEGV) not work?

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I don't know. I guess I stopped at the first thing I tried that worked.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

baby puzzle posted:

I use it to test my crash handlers because abort() doesn't work for that.

Which solution isn't lovely?

Get an aligned pointer, memprotect it unwriteable, write to it.

more falafel please
Feb 26, 2005

forums poster

Xarn posted:

Does raise(SIGSEGV) not work?

Not every platform is Unix. Basically every platform (not all!) will crash if you write to address 0.

Xerophyte
Mar 17, 2008

This space intentionally left blank

baby puzzle posted:

I use it to test my crash handlers because abort() doesn't work for that.

Which solution isn't lovely?

raise is intended for that sort of thing and will guarantee that a specific signal handler is called. I'm sure there's a lot of fun OS-specific behavior around this so maybe it's not always sufficient, I don't honestly know.

It's not the end of the world to cause a crash in some other way of course, the problem is that it's surprisingly hard to write crashing code that doesn't rely on undefined behavior. *((unsigned volatile int *)0) = 0xDEAD specifically is undefined so your compiler may decide that it's unreachable and optimize it away or otherwise pull your rug out from under you in interesting ways. It probably wont, but it's still a pretty brittle approach.

OddObserver
Apr 3, 2009
Hmm, what are semantics for integer divide by zero at the language level?

Qwertycoatl
Dec 31, 2008

OddObserver posted:

Hmm, what are semantics for integer divide by zero at the language level?

In C, it's undefined. Also in C++ I think.

Xerophyte
Mar 17, 2008

This space intentionally left blank
From the latest draft in glorious standardese:

https://github.com/cplusplus/draft/releases/tag/n4849 posted:

7.1.4 If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined. [Note: Treatment of division by zero, forming a remainder using a zero divisor, and all floating-point exceptions varies among machines, and is sometimes adjustable by a library function. — end note]"

So, yeah, undefined in the language.

Xarn
Jun 26, 2015
I strongly recommend eel.is (e.g. https://eel.is/c++draft/expr.pre#4) and non-numbered links for referring to standardese :v:


more falafel please posted:

Not every platform is Unix. Basically every platform (not all!) will crash if you write to address 0.

raise is part of the C (and thus C++) standard library, and while the implementations are allowed some latitude in dealing with it (namely, the default handler is allowed to plain ignore the signal), it is much saner way to ask for SIGSEGV on most platforms that support C++ than to invoke UB and cross your fingers that optimizer will not do stupid poo poo with it.

(And yes, raise works on Windows by default)

pseudorandom name
May 6, 2007

more falafel please posted:

Not every platform is Unix. Basically every platform (not all!) will crash if you write to address 0.

signal() and raise() are part of the C standard.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Even putting formal semantics aside, some architectures define integer division by zero to yield zero instead of trapping, including MIPS and ARM64.

Spatial
Nov 15, 2007

Right. Not all CPUs were originally designed as calculators. :v:

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

pseudorandom name posted:

signal() and raise() are part of the C standard.

This is true, but it’s not clear to me that the semantics of raise(SIGSEGV) are standardized to have the effect that’s desired here. It reads to me (though I can’t seem to copy from the PDF in my browser; 7.14.2.1 and 7.14.1.1 in C11) that it basically just calls the established signal handler, and not that it would necessarily and portably result in program termination or similar. It certainly seems permissible that SIGSEGV could be ignored by default, at the implementation’s discretion.

POSIX seems to be where the desired semantics are specified, rather than C11.

Xerophyte
Mar 17, 2008

This space intentionally left blank
I think you're right that SIGSEGV can be ignored by default, but that's because the standards don't require an implementation to detect or have any invalid memory access errors at all. They can only require that explicitly raising a SIGSEGV signal calls your SIGSEGV handler if you have defined one, since that places no requirements on the platform. On platforms with advanced features like interrupts and memory access failures I think you may expect that calling the handler is in fact equivalent to forcing an actual error, same as POSIX specifies. I may also be horribly wrong about that and about to be annoyed as someone informs me that windows does this stupidly in some fun way.

Anyhow, for the purpose of checking that your bespoke diagnostic signal callback works, explicitly calling the signal handler with raise should to my knowledge be as good as forcing an actual invalid memory access. For the purpose of forcing the CPU to trap raise is less useful, but then you're well outside of things defined by C and C++ language semantics.

I don't know exactly what the purpose was for the wtfunction thing that spawned this discussion. Odds are that if the objective is to terminate uncleanly on some specific platform then there's a better way to do that than trying to wrangle a write to a null address in an undefined way.

Adbot
ADBOT LOVES YOU

Beef
Jul 26, 2004
Didn't some embedded systems put the interrupt vector at address 0? :p

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