|
I love C++ primarily because I like the type of projects where C++ is the best solution. This is the approach I recommend--what kind of projects do you want to work on? Then ask what platforms you want to target and in what way. (For example, if you want a rich native GUI experience on Linux and Windows, C# won't work, but C++ with Qt will.)
Also be aware that C++ has an incredibly rich set of libraries available in addition to the standard library.
|
|
|
|
|
HS_C_Student wrote: That C++'s OOP leads to less resource efficient programming and that classes were a crutch to help structure code in lieu of skillfully choosing one's own good designs.
There are so many ... misconceptions in that sentence alone, I wonder why you're actually thinking of C++ as your next language. I do agree that C++ is a good language to learn, but maybe I should clarify a few things:
1. C++ is not an OOP language! While it's often declared as such because its support for OOP is the most prominent feature that distinguishes it from C, C++ (as well as C) is a general purpose language! You can use it effectively for pretty much any programming paradigm you can think of: procedural, modular, object oriented, functional, you name it. Most other programming languages are not nearly as flexible. And that is the main reason why I love this language more than any other.
2. C++ is not less efficient than C. Neither with respect to use of resources nor with respect to speed. It used to be somewhat slower in some areas, but not the assembly that modern compilers can generate from modern C++ code. Of course, if you turn, say, some procedural code into OO code, use a lot of virtual functions and class hierarchies, that will likely cause some losses - but (if you do it right) you get clearer, more comprehensible code in return. It's not really a loss, it's a tradeoff, and it's for the programmer to decide whether he's willing to make that tradeoff or not.
3. I'm not sure what gave you the impression that classes are a crutch!? When I look at some code from less skilled programmers, yes that code may appear that way. But if you do understand the OO principles, and use it correctly, a well designed class hierarchy can give you extremely clear and comprehensible code, without sacrifcing anything, really.
That said, I'll have to give you a fair warning: programmers coming from a C background tend to stick with the programming techniques they know, because, in C++, they can! That is not necessarily a bad thing, but when these techniques creep into the class design, then, yes, what you get is a crutch! When you move to C++ from C, you need to take a step back every time you're about to design a class, and make sure that you drop any notion of using known principles and techniques, until you at least managed to specify what, exactly, the class needs to be able to do - and what not! The latter is really the key to good class design: making sure that a class does no more than what it's intended for. Otherwise you won't be able to benefit from the good aspects of OO, and you'll end up with the worst aaspects of both the procedural and the OO paradigm.
4. One extra tip: as I said, OOP is just one of many paradigms that C++ supports. Don't get too crazy with classes! The perception of many programmers that C++ is an OO-language, and only an OO-language, led to massive overuse of the OO principles. Programmers (including myself) were suffering from "when all you have is a hammer, everything looks like a nail" syndrome. It is not a good idea to turn everything into classes just because you can. Sometimes a struct and a set of polymorphic (or otherwise generic) functions is better design.
Therefore, when learning C++, you should also learn about the other paradigms: templates, generic programming and meta programming are diffcult to understand and learn, but there are many good articles and sites, and you can always come here for help. Functional programming got a lot of support with the more recent C++ standards and are well worth investigating. And, of course, sometimes there's really nothing wrong with plain old C structs and functions.
C is a great toolbox. But it's just the starter set with little more than a hammer, a screwdriver, and pincers. With C++ you get the advanced toolset! That doesn't mean you no longer need your hammer. Just that you now have a lot more specialized tools that can make specific tasks so much easier to complete.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Excellent description ... especially dispelling the myths and misconceptions.
|
|
|
|
|
It seems to me that C will not die completely yet. Projects will exist, vacancies will be open.
I like object oriented languages. Therefore, I would advise working with them. Even without knowing the syntax of the language, just knowing and understanding OOP, you can quickly learn a new language
|
|
|
|
|
Hi,
Am working in simulation we are going to develop OPC sever DA3 and OPC client DA3 in VC++(MFC). Can you suggest which vendor software suitable for us. If you know any one please provide the link.
|
|
|
|
|
|
I have included CLIstCtrl in VIe wcalss in OnCreate(). I added headers details in OnCreate(). I want to add check box in Second column on control. If i add extended style LVS_CHECKBOXES, it adds checkbox to first column. But i want that for second column, how can i do that?
m_ctLstCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT ,listRect, this, IDC_TRENDLISTCTRL);
m_ctLstCtrl.SetExtendedStyle(m_ctLstCtrl.GetExtendedStyle() | LVS_EX_GRIDLINES| LVS_EX_FULLROWSELECT| LVS_EX_ONECLICKACTIVATE );
m_ctLstCtrl.InsertColumn(0,_T(""),LVCFMT_RIGHT,20);
m_ctLstCtrl.InsertColumn(1,_T("Visible"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(2,_T("Status"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(3,_T("Trace color"),LVCFMT_LEFT,50);
m_ctLstCtrl.InsertColumn(4,_T("Object"),LVCFMT_RIGHT,100);
m_ctLstCtrl.InsertColumn(5,_T("Object"),LVCFMT_RIGHT,100);
m_ctLstCtrl.InsertColumn(6,_T("Object Desc"),LVCFMT_RIGHT,100);
In OnTimer() im adding data to this Listctrl as
TagListctrl.SetRedraw( FALSE );
TagListctrl.DeleteItem(iTagPos);
index = TagListctrl.InsertItem(iTagPos,indexno);
TagListctrl.SetItemText(iTagPos,4,"Object");
TagListctrl.SetItemText(iTagPos,5,sName);
TagListctrl.SetItemText(iTagPos,6,sDesc);
TagListctrl.SetRedraw( TRUE );
Anu
|
|
|
|
|
You could try to rearrange the columns moving the first one to the second place.
|
|
|
|
|
The LVS_EX_CHECKBOXES style applies to the entire ListView item, not to a specific subitem.
|
|
|
|
|
Ring3 I can get Module entry point and Module Path through “ZwQueryVirtualMemory”,I dont know how to use “ZwQueryVirtualMemory” get Module Size pls tell me
|
|
|
|
|
I am going nuts with this test code.
Two dimensional array and my test objective is to find matching first element in the arrays.
It works fine "scanning " for 0xA as it should , goes crazy when I try to look for 0xB0.
I hope is is something stupid I am overlooking.
Hope any extra pairs of eyes will spot the problem.
#define COMMAND_LIST 16
int8_t ILI9341_Command_List[][COMMAND_LIST] = {
{ 0 },
{ 1 },
{ 4 },
{ 6, 7 , 8 },
{7},
{0xA,8,9,10,11,12},
{0xB0,8,9,10,11,12},
{9}
};
uint8_t ProcessCommand = 0xB0; int index = 0;
do {
cout << "SCAN ProcessCommand " << hex << +ProcessCommand << "@ index "
<< dec << +index << endl;
} while (ILI9341_Command_List[index++][0] != ProcessCommand);
|
|
|
|
|
because 0xb0 is negative in 8 bits? You are comparing a uint8_t (unsigned) with an int8_t (signed)
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you.
I knew I was getting too tired and that it was something STUPID I missed.
|
|
|
|
|
Compiling with all the warnings enabled (e.g. -Wall option, for g++ ) would help.
|
|
|
|
|
Thanks, I'll check that.
I do not want to make excuses , but I think I just copied the test code and missed the "u" , but I did get some - (minus) output when it went crazy.
|
|
|
|
|
I can do multidimensional array , no problem.
What I need is
sort of " multidimensional array of single variable and variable length array ".
The main array is defined / assigned (?) and of "fixed length" - three in example - for now.
Of course I need to access all using pointer.
How do I accomplish this ?
PS I did try std:array , but it conflicts with "boost" - can't do for now.
int Array [3][2] = {{2, 5} , {3,1} , {4,9}}; multidimensional array OK
int Array_Array [ ??? ] = {
{{1} ,{2, 5 ....}}, {single element} , {array...}
{{2} ,{2, 5 ...}},
{{3} ,{2, 5....}}
};
Help will be appreciated.
Cheers
Vaclav
|
|
|
|
|
Use a class or structure which has pointer for the second variable:
struct foo
{
int first;
int* second;
} fooArray[];
|
|
|
|
|
If you have an two-dimensional array where each row has a differing number of elements, why not use a std::vector?
std::vector<FOO> foo2DArray[];
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I think you meant this answer for Vaclav.
|
|
|
|
|
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Thanks, just what the doctor ordered.
Then I can add another member to the struct if I want.
Nice and clean solution.
|
|
|
|
|
Yes, if you are using a struct you can have many different items inside it. Also, as Daniel mentions below (to me) you may want to use a std::vector rather than a simple array.
|
|
|
|
|
Here is my test code.
It is not very "dynamic" but will do for now.
I may add the "Command" as a first element in Data array to make sure they match.
Actually it would simplify things (a little ) - using just multidimensional array with first element being "Command".
But I like the struct for future....
Now I need to modify usage of Command /Data....
#define COMMAND_ARRAY 16
struct ILI9341 {
int Command; int* Data; } ILI9341Array[COMMAND_ARRAY];
int index = 0;
int dataIndex = 0;
int DefineCommand[COMMAND_ARRAY] = { 0x0, 0x1, 0x4 };
int DefineData[][10] = { { 1, 2, 3, 4 }, { 5, 6, 7 }, { 9, 10, 11, 12, 13,
14 } };
for (index = 0; index != 3; index++) {
ILI9341Array[index].Command = DefineCommand[index];
#ifdef DEBUG
cout << "ILI9341Array[" << dec << +index << "] Command 0x" << hex
<< ILI9341Array[index].Command << endl;
#endif
ILI9341Array[index].Data = DefineData[index];
#ifdef DEBUG
do {
cout << "ILI9341Array[" << dec << +index << "] Data[" << dec
<< +dataIndex << "] 0x" << hex
<< ILI9341Array[index].Data[dataIndex] << endl;
} while (ILI9341Array[index].Data[++dataIndex]);
dataIndex = 0;
#endif
}
|
|
|
|
|
That's way too much typing. Consider:
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
using namespace std;
#define DEBUG
int main()
{
map<int,vector<int>> IL9341Command = {{ {0x0, {{ 1, 2, 3, 4 }} },
{0x1, {{ 4, 6, 7, }} },
{0x4, {{ 9, 10, 11, 12, 13, 14 }} },
{0xff, {{ 44, 55, 66, 77 }} } }};
#ifdef DEBUG
for(auto iter : IL9341Command) {
cout << "IL9341Comand [ 0x" << hex << iter.first << " ] =";
for(auto cmd : iter.second)
cout << " 0x" << hex << cmd;
cout << endl;
}
int *data = IL9341Command[0xff].data();
cout << "\nCommand[0xff] data :";
for(size_t i = 0; i < IL9341Command[0xff].size(); i++)
cout << " 0x" << data[i];
cout << endl;
#endif // DEBUG
return 0;
}
You can access the command data directly if you know the key via IL941Command[key], without having to iterate through the array, and as shown above, access to the "raw data" can be gained by calling data() on the vector. If you have C++17 then you can simplify the for(auto iter ...) loop as follows
for(auto [key, data] : IL9341Command) {
cout << "IL9341Comand [ 0x" << hex << key << " ] =";
for(auto cmd : data)
cout << " 0x" << hex << cmd;
cout << endl;
}
modified 20-Jan-19 15:07pm.
|
|
|
|
|
Hmm. Not sure why the code didn't format properly within the <pre code="C++"> tags. I looked closely and there wasn't any tags in the code as posted. Also, how does one post code with preprocessor directives in column one without them turning into (h1) header lines?
Edit: the format issue with the code was because I needed to convert "<" into <.
modified 20-Jan-19 15:09pm.
|
|
|
|
|