Translating new C++ to old C++ [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
C++11 and C++14 introduce a lot of new features that make programmers' lives easier. However, in various environments (e.g. CUDA), support for the most modern C++ features may be weak or nonexistent.
Many of these features (e.g. auto, decltype, constexpr, variadic templates) do not add any challenges to code generation, and really only require a parser that understands the constructs. In principle, unless honestly new functionality (e.g. thread_local) is used, there could be a tool that takes C++14 code and converts it into something that could be built with something that only understands the C++03 language.
Does such a tool exist? (or are my presumptions way off base?)

AFAIK no such tool exist. Some C++ compilers (the original Cfront, and perhaps Comeau C++) generated C code.
You might customize GCC (e.g. using MELT) to translate the internal Gimple representation to a small subset of C++. This is a lot of work (and the emitted C++ won't be portable).
Maybe you should consider OpenACC

Related

Is there unit tests for STL containers? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Is there ready unit tests for testing if STL containers are working correctly, something that was used by compiler creators?
I'm making a simple port of the STL in C and need to test the data structures and thought that STL unit tests already existed, but didn't find anything
Is there unit tests for STL containers?
STL does not exist anymore. Read the C++11 standard n3337 and see this C++ reference website. Consider also using Boost.
Both recent GCC and recent Clang provide testsuites for the standard C++ containers library, whose implementation is practically tied to the compiler (because of compiler optimizations)
I'm making a simple port of the STL in C
Then look -at least for inspiration- into Glib (from GTK) and SGLIB. I tend to think that you could use one of them. Given the complexity of the standard C++ library, I believe you won't be able to make from scratch in just a few weeks a simple port of it to C if you care about efficiency. Look also into MILEPOST GCC and read this paper then Artificial Beings: the conscience of a conscious machine ISBN:9781848211018 for some interesting insights.
Otherwise, be sure to read Introduction to algorithms
Notice that with some care, you usually can write in C++ a library callable from C (use extern "C" appropriately and systematically). A good example is of course libgccjit (which you could consider using, for some partial evaluation based approaches: you might generate specialized machine code suited to particular instances of your problems).
If you code your generic container library in C, consider using Frama-C on it, and with a recent GCC, compile it with all warnings and static analysis options. You might even consider writing your GCC plugin to check that users of your library are using it correctly.
See also the European DECODER project.

How to read/interrogate a filesystem and file structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
As a first time programming using vi with a raw Linux terminal in C++, what is the simplest way to recurse through a filesystem and get results such as file size, date, directory date etc?
I imagine I'm missing a library or two that would handle this pretty cleanly which would be great to know. Even better would be knowing where to find a solid reference for the basics like this.
If you have a modern compiler you can use std::filesystem:
https://en.cppreference.com/w/cpp/filesystem
Otherwise you can use boost::filesystem, which is very similar but non standard:
https://www.boost.org/doc/libs/1_67_0/libs/filesystem/doc/index.htm
Boost is a collection of libraries with various purposes and a focus on quality. Boost libraries regularly end up in the new C++ standards so it's good thing to learn.
You might consider (on Linux at least) to use nftw(3). You could use opendir(3) + readdir(3) + closedir with stat(2) (and nftw is using all these). See also syscalls(2) (and read some Linux programming book, perhaps the old ALP). Notice that on Linux (and POSIX systems), the operating system API is in C, not in C++.
Of course, you might use the C++ functions given in f4's answer (they are are based on functions above).
And you could use C++ frameworks such as boost, poco, Qt (also using the functions above).

What are the silent changes of behaviour when updating c++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Consider a C++98 code base that I would like to update to C++14.
I really want to do this upgrade as it would benefit the code base gratelly, the question is the burden of such update.
The problem is that this code base does not have a comprehensive test suite. Therefore after updating, some changes of behaviour that would not get caught in compile time, might go unnoticed.
Now, I know the standards comittee rarely introduces breaking changes, especially silent ones, and yet some changes are inevitable.
For risk analysis and timeline purposes of upgrading the language version I need to know the following:
Is there a comprehensive (or partial) list of such changes?
Is there an automated tool that can point to potential instances of silent breakages in my code base (to be fixed manually)?
The C++ standard itself has such a list. I believe it isn't entirely comprehensive (especially if you do things that often work in practice but aren't allowed by the standard, like extending the std namespace in unsupported ways.
If you look at Appendix C of the C++14 standard, you see that it lists differences between C++17 and older versions of C++ going back to C++03. Section C.1 is irrelevant for your purposes because it's a comparison with C, but C.2 and C.3 is probably helpful.
If you want to convert to another standard instead (C++17 is currently the most recent published version and I'd highly recommend migrating to that if you're migrating anyway), you can find links to those in browsable HTML form here. Note that none of these are the official standard, but they are very close; the only differences are minor editorial fixes in one direction or the other.
I am not aware of any automated tools to help with the migration, but I wouldn't be surprised if any existed.

Generate list of types from C++ header file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I have implemented a reflection engine in C++, and I can construct types and add them to the reflection database like so:
TypeInfo* spark_math_Vector2_type = new TypeInfo();
spark_math_Vector2_type->setName("Vector2");
spark_math_Vector2_type->setFullName("::spark::math::Vector2");
spark_math_Vector2_type->setHash(typeid(spark::math::Vector2).hash_code());
spark_math_Vector2_type->setSize(sizeof(spark::math::Vector2));
Reflection::getInstance().registerType(spark_math_Vector2_type);
However, I now want to automate the generation of the type database. To do this I need a way of getting all of the types created within C++ headers, and the constructors / methods / fields of the types.
I have found gccxml, however it has various drawbacks (being too slow etc). Is there any other exiting tool / framework available? Or maybe there is a better way of doing this? (I really do not want to have to write a parser...)
Basically your choices are:
Edison Design Group front end
GCC (GCCXML is derived from this)
Clang
(Our) DMS Software Reengineering Toolkit with its C++14 front-end
EDG is commercial, but I think free for research purposes. GCC wants to be a compiler, and will tend to fight you trying to bend it to other purposes. Clang seems well designed for tasks like this. We think DMS (also commercial) is well designed for this.

tools to help minimize usage of macros in C++ programs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Different C++ style guides deprecate the use of C Preprocessor macros.
I know there are tools which help detect errors due to macro usage (CPPCHECKER, Check), and tools which provide refactoring in the presence of preprocessor directives (CSCout, XRefactory).
I was wondering if there are any refactoring tools that suggest alternatives (like inline functions, constant expressions) to macros in C++ programs.
Years later it seems that your work is being used as a basis for such tools since there were none present before.
Macronator which later became part of Cevelop IDE is a tool that can refactor object-like and function-like macros to equivalent c++11 expressions. They reference "The demacrofier" paper by by Kumar, Sutton, and Stroustrup as a base for their software. I used it to remove ~15k macros from a codebase.