|
|
ForNow wrote: As MSVC only goes to C++ 11
No, it fully supports C++20.
Go to project properties pages -> General -> C++ Language Standard and select "ISO C++ 20 Standard".
Now, for that particular piece of code, the "{}" is the C++ initialization syntax available since C++11. You can try replacing that with:
auto ret = procpointer->extsymcollector->insert(T(*s, *exsympointer)); where T is the type of object that is inserted.
Mircea
|
|
|
|
|
David Crayford who works on the XL C\C++ z/os compiler suggested I switch my compiler from MSVC to CLANG\LLVM for a few reason one then seems to be easier portability
What’s your opinion
Thanks
|
|
|
|
|
I'm a MSVC and Visual Studio fan. I find it a superb development environment. Compiler is just one piece of the puzzle, but you also need a good editor and a good debugger. All in all, for day to day development, I think Visual Studio is hard to beat. More than once, after developing in Visual Studio I had to port to g++ and I never had any major problems.
Mircea
|
|
|
|
|
|
Mircea Neacsu wrote: No, it fully supports C++20.
Can you independently document that?
Years ago (decades) there was at least one source that did a detailed comparison between compilers to see which ones were most compliant. This was after ANSI C++ was release.
Microsoft did poorly in that comparison.
Then someone sued to prevent such comparisons. Or perhaps added end use license terms that prevented such comparisons. If Microsoft did not start that they certainly participated in it.
So my question then, as it goes back to the first one, is how do you know how compliant they are?
|
|
|
|
|
|
|
Hello friends ! , in my following code in C I want to invert my linked list in the display using a 𝗿𝗲𝗰𝘂𝗿𝘀𝗶𝘃𝗲 𝗳u𝗻𝗰𝘁𝗶𝗼𝗻 ; but the code does not work !! Is there an error; thank you for mentioning it :+1:
#include<stdio.h>
#include<stdlib.h>
struct cellule{
int a;
struct cellule *suivant;
};
//Recursive function to display the list in invers order
void affichage (struct cellule *liste){
while (liste!=NULL){
affichage(liste->suivant);
printf(" %d “,liste->a);
}
}
int main()
{
struct cellule *liste,*p,*q,*r;
int n,i;
printf(“Donner le nombre d’elements de la liste:\n”);
scanf(”%d",&n);
printf(“Entrer les elements de la liste:\n”);
for(i=0;i<n;i++)
{
p=(struct cellule="" *)malloc(sizeof(struct="" cellule));
scanf(“%d”,&(*p).a);
if(i="=0)" liste="p;
else" (*q).suivant="p;
q=p;
}
affichage(liste);
printf(“\n”);
system(“pause”);
return" 0;
}<="" pre="">
|
|
|
|
|
There are two issues:
1. Where you create the cellule structures:
for(i=0;i<n;i++)
{
p=(struct cellule *)malloc(sizeof(struct cellule));
scanf("%d",&(*p).a);
if(i==0)
liste = p;
else
(*q).suivant=p;
q=p;
}
q->suivant = NULL;
2. Your recursive method
void affichage (struct cellule *liste){
if (liste ==NULL) {
return; }
affichage(liste->suivant); printf(" %d ",liste->a); }
|
|
|
|
|
By "inverted" do you mean you want to print your list in reverse order?
E.g.
input: 1 2 3 4 5
output: 5 4 3 2 1
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
If you're having problems understanding that, then you really do need to take a step back, find a good resource for learning C++ and work your way through it. This is simple, basic C++ stuff that you should be able to grok, almost without thinking about it. Using more basic types
class C {
public:
int n;
C() { n = 0; } };
C c; C *pc; C *pc2 = new C();
But these days you really should be using smart pointers instead of new/delete. See the documentation for std::shared_ptr and std::unique_ptr here: [Dynamic memory management - cppreference.com](https://en.cppreference.com/w/cpp/memory)
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Every C++ class has a constructor that gets called when the object is created. So if we have
class C {
public:
int n;
C() { n = -1; }
}
int main()
{
C c; std::cout << c.n << '\n'; }
In the class C given above, if you do not give a default constructor, then the compiler will provide one, but it will not initialize the value of C.n
class C {
public:
int n;
};
int main()
{
C c; std::cout << c.n << '\n'; }
Presumably class QBluetoothLocalDevice provides a default constructor that fills in reasonable default values for its members. If some of those members use system resources (e.g. open file handles, memory, etc), then there is also a destructor that gets called when the object goes out of scope to release the resources (e.g close open files, release memory, etc).
Keep Calm and Carry On
|
|
|
|
|
Member 14968771 wrote: Do I have to look thru the QBluetoothLocalDevice class documentation to find which method makes the "test" to contain all the hardware info? Yes, as you would need to do with any class that you are using. And here it all is: QBluetoothLocalDevice Class | Qt Bluetooth 6.4.2[^].
|
|
|
|
|
The first one creates an instance on the stack. It will be destroyed when it goes out of scope.
The second one creates an instance in heap memory*. It will not be automatically destroyed and you should call delete to destroy it.
*Unless new has been overridden to do something unusual.
|
|
|
|
|
1. Create an object on the stack
QBluetoothLocalDevice localDevices;
This reserves all the memory space required for a QBluetoothLocalDevice object on the local stack. It then calls the constructor of the class to initialise any parts of that memory as specified in the class (see answers by @k5054). The variable localDevices holds the address of the object (even though it does not appear to be a pointer).
2. Create an object on the dynamic heap, and return a pointer to it.
QBluetoothLocalDevice *localDevices_new = new QBluetoothLocalDevice();
In this case the memory is requested from the heap, the constructor called to initialise it, and its address returned and saved in the pointer localDevices_new .
The end result is much the same in both cases, apart from the location and lifetime of the two objects. In case 1 the object only exists within the function where it is created; it is automatically destroyed when the function ends. In case 2 the object exists until it is destroyed by the delete statement, or the program terminates.
But as suggested elswhere, this is basic C++, which you should have learned and understood long before you charged down this rabbit hole that you currently find yourself in.
|
|
|
|
|
Member 14968771 wrote: This is a test
in few words of plain English ,
Which suggests homework.
But the answer is no.
The question cannot be answered in "plain english" because it require concepts that only exist in programming. So as the other answers suggest one would need to understand what a 'local variable' is and what a 'heap' is for any answer to make sense.
|
|
|
|
|
It's not homework. This member is struggling with basic concepts in C++.
|
|
|
|
|
Please follow up if the explanations helped.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
oh well, suit yourself.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
I've tried e.g. QueryThreadCycleTime as follows:
#include <windows.h>
#include <iostream>
int main()
{
for (int i = 0; i < 10; ++i)
{
uint64_t n1 = 0, n2 = 0;
BOOL ok1 = QueryThreadCycleTime(GetCurrentThread(), &n1);
BOOL ok2 = QueryThreadCycleTime(GetCurrentThread(), &n2);
if (ok1 && ok2)
std::cout << n2 - n1 << "\n";
else
std::cout << "n/a\n";
}
}
Typical results are:
1036
1114
1734
748
706
670
652
716
652
666
The numbers vary widely - ok, maybe these are expensive calls - but what is the point then?
If I replace the thread cycles with process cycles, numbers get even weirder:
BOOL ok1 = QueryProcessCycleTime(GetCurrentProcess(), &n1);
BOOL ok2 = QueryProcessCycleTime(GetCurrentProcess(), &n2);
With typical results:
39666
39520
304964
145932
47486
287156
191528
208652
196176
288642
This blog post[^] suggests that it should be no worse than QueryPerformanceCounter , but that's not what I'm seeing.
Anyone with insights?
|
|
|
|
|
The number of CPU clock cycles used by the threads of the process. This value includes cycles spent in both user mode and kernel mode. . So it just shows which threads are consuming what. That may allow you to tune your application if it is largely compute bound.
|
|
|
|