Which library - std::chrono::system_clock [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Which .dll file contains "std::chrono::system_clock" method?
I can't find any useful information in the documentation.
EDIT:
I want to create my own version of the function, so I wanna rebuild the file and replace it in the import table of my own application

All you need is to #include <chrono>. No further deployment needed.

Well, without knowing your actual goal ("knowledge over rules", you said) it is impossible to tell you the right way to achieve it. I can only tell you that this is not it.
I just want to do that if it is possible
For some value of possible, maybe.
It's possible that the code for this type is defined right there in the header, rather than built into the runtime. So, you would only "need" to modify the header. But then what about the rest of the runtime that expects the type to look a certain way? You've just violated the one-definition rule at the first hurdle.
It should go without saying:
DO NOT DO THIS.
Your program has undefined behaviour when you modify the standard library, even if you can somehow manage to get enough controls of your implementation's internals to make it work without crashing and/or catching fire.
To do this "properly" you would have to fork and rebuild the entire standard library implementation so that its contents are consistent. Good luck with that.
Instead, if you want to use a type that looks like std::chrono::system_clock (it is not a "method", or member function — it is a class) but acts differently, then define such a type yourself in your own namespace.
People have been doing this, when mocking implementation functions, for many years. Your unit testing framework should come with some documentation that teaches you how to mock functionality successfully and reliably.

Related

c++ cout vs printf() [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
After learning about c++ through a couple different sources, I found conflicting advice concerning the use of cout/printf(). One source said that printf(), and I quote:
... does not provide type safety, so it is easy to inadvertently tell it to display an integer as if it were a character and vice versa. printf() also does not support classes, and so it is not possible to teach it how to print your class data; you must feed each class member to printf() one by one.
So, the more important thing to me would be the readability factor of using printf(). On the other hand, another source mentioned that cout, with its use of the overloaded operator <<, uses more instructions to execute and can therefore be more expensive in terms of memory over a large program. Although, the person who said this was a systems programmer, in which every bit of performance is vital. But say I wanted to go into game or application development.
Would the performance differences between printf() and cout matter all that much?
In general, does it really matter what I choose to use in an application program?
Thank you for any input.
You would measure the differences on your particular implementation for your specific use case and determine that for yourself.
I would say both lines of reasoning in the question have merit, but you can't generalise about performance.
If you want to go into game or application programming, printf/cout won't be needed too much. The only use in these cases is for debugging.
If you really need to use printf/cout a lot, the difference will be when writing a huge amount of data, otherwise you don't need to bother.

In C++, are custom header files optional? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This was asked on a past exam. Given that the header file is custom I am assuming not because they are just variations of the main(){ header correct?
I'm not sure if I understand the question, but I would say yes, they are optional. You could write all of your (custom) functions, classes, etc. in one file if you wanted.
I'm new here so I can't comment, but the question is a bit confusing to me. But here is what I think, I hope it helps:
Header files contain functions, variables, classes etc. in C and C++. Header files that come pre-built with your compiler must be included before you can use any function or anything thing inside that file.
Now referring to a custom header files, you may choose to create a file containing specific information to use in your programs, often to make your code look more organize or to create reusable libraries. Those are OPTIONAL simply because you can manage to create all your functions, variables and classes in the same file containing your main(){}. It might look messy, impossible to read but possible to achieve.
BTW I'm not sure about what you mean by header files being variations of the main(), but agreeing with Trevor Hickey, they shouldn't have a main() function since they are not compilable, they don't execute the functions they just hold the information.

Avoiding the windows header [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using both win32 and directx when making a game engine + game. Win32 directly needs the window header and directx header includes it aswell.
It is a decently-sized project and I'd rather avoid exposing the windows header to the rest of the project(s) if possible. Is there any good way to bypass this issue?
There's only one practical way to avoid exposing a header that your implementation code needs, and that's to include the header only in the implementation.
That's called the compiler firewall idiom.
Often (but this is not always required) one exposes a class with a member pointer to an object of declared but incomplete type, that is defined only in the implementation file. This is usually called the PIMPL, short for pointer to implementation, idiom, but it has also been called the handle-body idiom and the Cheshire Cat idiom.
One alternative to a PIMPL pointer is to declare a factory function in the header file, where that factory function produces objects of some known type Base, and in the implementation file let it produce an object of a derived type Derived that contains the dependencies on the undesirable header.
Another alternative, but then you might run into thread safety issues, is to just provide functions that operate on a static state variable. I.e. a singleton, a global. Yes this is as bad as it sounds (even though a whole programming language, Modula-2, was based on the idea), but it certainly is a technical option, and might be preferable in certain situations.

How to approach a C++ parser [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am wanting to have a go at a C++ parser for a formatter I am making.
You can obviously open a file and use getline(..) or get(), is this reasonable way of starting things off and then working out a system using vector arrays and hence creating loads of arrays and somehow structuring out and processing what you are doing from there. For example say I wanted to find ever function in a source file, all functions have the common syntax, "(){" once whitespace has been removed, so do you just look for common delimeters to parse out the sections into arrays. I suppose I will learn as I go.
Or I also assume there are tried and tested ways of doing this, and I would likley just be reinventing the wheel as they say.
C++ is a language that is quite hard to parse in the first place. So if you want anything other that really trivial C++ code to be "understood" by your parser, you are definitely better off starting with an existing product.
The Clang frontend library would perhaps be a good starting point.
There are also a number of "source to source" conversion examples based on clang. Here's one of them: http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/

disallow access outside of file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Now I know someone is going to say static or anon namespace without reading so let me just say no that is not what I'm looking for. What I am looking for is something that will allow me to kind of "quarantine" off a file in my code base so it can't access anything outside of that file so that if someone changes it it can't inadvertently screw things up elsewhere. Is this possible?
What I am looking for is something that will allow me to kind of "quarantine" off a file in my code base so it can't access anything outside of that file so that if someone changes it it can't inadvertently screw things up elsewhere. Is this possible?
For the most part, no, not as a part of the C++ language.
In order to accomplish your goal, consider one/some of the following:
Moving the code from your file into another library to reduce the likelihood of collateral damage
Providing "guarantees" by testing with dynamic tools like valgrind, Purify, ASan ("Address sanitizer"), Electric Fence
Making comments regarding the intended design of the code for this file ("isolated", "encapsulated", etc)
Build-time restrictions: dump the preprocessed output from the source file, flagging cases where new #includes (ones outside of a whitelist, e.g.) show up.
Have the file not include any headers from the rest of your project. Of course this doesn't protect against malicious coding, but then, neither does anything else in C++.