|
Member 14968771 wrote: ( ...but for some who cannot read it looks as QT problem...) Adding comments like that is unnecessary, and does not encourage people to help further.
|
|
|
|
|
Member 14968771 wrote: QTconcurent will not accept more than 5 parameters Reminds me of when I worked for a company about to publish a completely rewritten FORTRAN compiler: The release was pushed by one (significant) customer who had run into the old compiler's limit on 99 (ninety-nine) parameters to one function. The new compiler would allow 128 parameters, but it could easily be extended to 256 in future compiler versions.
I sort of accept that when going above a certain limit (isn't it 4 for the ARM ABI?), there is an increased cost. Five is probably acceptable. The day it grows beyond 99, I think you are on the wrong track
|
|
|
|
|
It reminds me of an adage or axiom or some such that my prof stated in class back in university days that went something like "If you function has more than 5 parameters, you've forgotten one!"
Keep Calm and Carry On
|
|
|
|
|
I merely said, "the documentation suggests ...". I do not have Qt on my system so I am not able to test it.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Try using nullptr instead of NULL. NULL is defined as a macro, often the equivalent of #define NULL ((void *)0) . That was fine for C, but C++ has stricter rules about converting to/from NULL pointers, so you should use nullptr, particularly when you want to pass a null pointer to a function.
Keep Calm and Carry On
|
|
|
|
|
Hope no one screams at me but if they do I guess its okay this question is simple its ridiculous
but here goes my total number in decimal is 1,621,270,208 the number I am trying to figure out the percent is from is 1,604,667,016
I did this calculation on the web and it came out to 98% the two number the first being total is a int the second unalloc is also a int. the variable percent is a double or float
I thought mistaking that percent = unalloc / total woudgive me 0000.98 in percent but I realize that since the quotient is zero percent is 000.000 doing percent = unalloc % total would give the reminder in percent and thus a value of 1604665335.000 I have searched the web I know this is real simple to some of you wonder if you could help
thanks in advance
|
|
|
|
|
Presumably you're doing something like
int total = 100;
int unalloc = 96;
double percent = unalloc/total;
So the problem here is that since unaloc and total are both int , the calculation is done in integer math, and then promoted to double. What you need to do is to promote either operand to the division to double (or both):
double percent = (double)unalloc/total:
Keep Calm and Carry On
|
|
|
|
|
that was it thank you so so so much
|
|
|
|
|
hey k5054 my comment does not relate to the currently running thread. I just wanted to let you know I keep getting back to some of your replies in topic I have posted quite a while ago. I thought it might be a good idea to let you know I`m haunting those posts.
|
|
|
|
|
Hey lookee here ... a joke icon!
That's what I needed the other day. Oh well.
|
|
|
|
|
double total = 1621270208;
double percentFrom = 1604667016;
double percent = percentFrom / total * 100;
|
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
If you pass a list of random types (numbers, strings, objects), then your function needs some method of determining what each reference is. That is why printf (and its derivatives) requires a format string to identify the type of each parameter.
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
I'm not sure exactly where you're stuck. But lets start with the example you gave in your original post:
void PrintFloats (int n, ...)
{
int i;
double val;
printf ("Printing floats:");
va_list vl;
va_start(vl,n);
for (i=0;i
Assuming that you're stuck here, then you might complete this something like
for(i = 0; i < n; ++i) {
val = va_arg(vl, float);
printf("%f ", val);
}
va_end(vl);
putchar('\n');
In this case I'm assuming that the int n parameter tells the function how many float values to expect. Other options to tell a variadic function how many arguments to expect are to use some sort of format string, like printf() does, or you can use some sort of sentinel value for your function e.g.
PrintFloats(1.1, 2.2, -15.2, nan("")); In this case we have assumed that a NaN won't be part of the input string, so is a fair choice for a sentinel.
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
It's pretty straight forward, really. When you use the va_arg macro, the second argument is the received objects type. So, to receive a pointer to a type, you use va_arg(args, Obj*) where Obj is some object type - e.g. class, int, double, struct, etc. Here's a short working example:
#include <cstdarg>
#include <iostream>
struct S {
int data;
S(int d) : data(d) {}
};
void f(size_t n, ...)
{
va_list args;
va_start(args, n);
for(size_t i = 0; i < n; ++i) {
S* ptr = va_arg(args, S*);
std::cout << ptr->data << '\n';
}
}
int main()
{
S item1(1);
S item2(2);
S item3(3);
f(3, &item1, &item2, &item3);
}
Keep Calm and Carry On
|
|
|
|
|
As I said, you need some control to identify hoe many parameters are being passed, and what type they are. There is no other way of knowing when you get to the end of the list.
|
|
|
|
|
I wrote this linked list code. Could someone confirm I`m doing it the way I`m supposed to.
class SomeNode
{
public:
int data;
SomeNode * next;
};
SomeNode * BuildList()
{
SomeNode * Tail;
Tail = (SomeNode*)malloc(sizeof(SomeNode));
Tail->next = NULL;
Tail->data = 100;
SomeNode * Temp;
bool firstrun = true;
for(int i =0; i < 5; i++)
{
if(firstrun)
{
Temp = AddTo(&Tail,i);
firstrun = false;
}
else
{
Temp = AddTo(&Temp,i);
}
}
return Temp;
}
SomeNode * AddTo(SomeNode ** Source, int somedata)
{
SomeNode * NewSN;
NewSN = (SomeNode*)malloc(sizeof(SomeNode));
NewSN->data = somedata;
NewSN->next = (*Source);
return NewSN;
}
|
|
|
|
|
- Since your code is C++ then why do you use malloc rather than new?
- How and where do you free your allocated in heap memory?
|
|
|
|
|
Thanks for your feedback Victor.
Since these are your only observations I take it that overall my code is within 'allowed' range.
malloc: Using it doesn`t seem to break anything so why not.
free: the code is just a display of how things would work in principle.
modified 18-Mar-22 7:20am.
|
|
|
|
|
One thing it is not good using malloc in C++ apps is because the class ctor is not called.
I see you are trying then to "solve" this problem using this code:
<pre lang="C++"> SomeNode * Tail;
Tail = (SomeNode*)malloc(sizeof(SomeNode));
Tail->next = NULL;
Tail->data = 100;
But you wiil need to do it in every place you will create the class instance and, moreover, after some updates in the class members you will have to look for all the occurrences of such a malloc and update the class member initializations accordingly!
|
|
|
|