|
I checked out the code at microsoft.com.
I am very new to C#. Could you explain the code in a little detail as I am not entirely sure what it does.
Thank you,
WHEELS
|
|
|
|
|
Ah, you are using C#, you are at the wrong forum here, try the C# forum[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
cpuh header is not supported by my compiler .. What should i do to make it support.?
Regards
$iva
|
|
|
|
|
What is 'cpuh' header?
As it stands, neither my compiler supports it, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Maybe it stands for "ComPiler Unsupported Header"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Sure!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Code-o-mat wrote: Maybe it stands for
CodeProject User Help me pleeeezzzzz it's urgent
led mike
|
|
|
|
|
You will have to give us more details, we do not have enough information to be able to help you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
any way thanks for all your funny replies ...
Regards
$iva
|
|
|
|
|
Hello,
this is quite a newbie question but I would appreciate a lot your help..
Let's suppose I want to implement an algorithm that behaves like the matlab "diff" command, that is given an input array of size N [x(1)......x(n)] it returns an array of N-1 elements [x(2)-x(1) .... x(n) - x(n-1)], like a sort of discrete derivative.
I would like to avoid to use vectors but simply arrays. The problem is I don't know how to create the second array of size N - 1. I could compute the size a priori and pass it as a parameter, but if I write
float* OUTarr = diff(float* INarr)
int size = sizeof(INarr)/sizeof(float);
float OUTarr[size];
two problems arise: first the size is always one (not depending on the real size of INarr) and second there's a compiler error 'expected a constant size'.
The same appears if I pass the size as a parameter of the function.
I know that allocation for arrays is static and actually I can't know the size of the array at compile time, but I could always know the exact size of the array before its allocation, so I shouldn't require the use of dynamic memory...
Thank you in advance for any suggestion!
L.
|
|
|
|
|
Your code has another problem: if you build the array inside the function, as local storage, you cannot return it.
If you're stuck with the above (IMHO bad) design, you may try with a template function, for instance
#include <stdio.h>
float alfa[10]={0,1,2,3,4,5,6,7,8,9};
template <int N>
float * diff(float a[N])
{
static float b[N-1];
for (int i=0; i<N-1; i++)
{
b[i] = a[i+1]- a[i];
}
return b;
}
void main()
{
float * beta = diff<10>(alfa);
for (int i=0; i<9; i++)
{
printf("beta[%d]=%f\n", i, beta[i]);
}
}
Please note: the static allocation of b is just a workaround, there are better ways to do it (for instance, the caller may provide storage for b ).
Moreover, personally, I prefer dynamic memory allocation for such a task.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
LostPitch wrote: I know that allocation for arrays is static
Only when they're allocated on the stack.
What's wrong with allocating the array on the heap:
float* diff(float* inArr, size_t inArrSize)
{
float* outArr = new float[inArrSize-1];
for(size_t i=0;i<inarrsize-1;++i)>
{
outArr[i] = inArr[i+1]-inArr[i];
}
return outArr;
}
Yes, you need to deallocate it after it's been used with delete[] , but hey - it works!
Also - what's with the use of float ? Doubles have more bits and are also faster, as floating point hardware is double or bigger internally and has performance penalties for converting to and from single precision floating point data.
LostPitch wrote: I would like to avoid to use vectors
Again - why? vectors (certainly after the TR1 update to the C++ standard) are guaranteed to be as efficient as arrays. They also do all the memory management for you. What's not to like?
|
|
|
|
|
Stuart Dootson wrote: What's wrong with allocating the array on the heap
That you should at least check for the allocation result.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Why? I use a modern C++ system that throws when new fails
|
|
|
|
|
OMG another ot those terrible over-the-top-youngster-developers!!!!!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: youngster
I wish...
I first programmed in C on my ZX Spectrum[^] around 1984. Can you imagine compiling in C (think headers...) when your only storage is a tape deck?
|
|
|
|
|
Stuart Dootson wrote: I first programmed in C on my ZX Spectrum[^] around 1984.
That time i was only few months old
BTW: THHB in action
Regards,
Sandip.
|
|
|
|
|
Stuart Dootson wrote: I first programmed in C on my ZX Spectrum[^] around 1984.
I did the same.
Stuart Dootson wrote: Can you imagine compiling in C (think headers...) when your only storage is a tape deck?
C ? I started with BASIC , but soon passed to Z80 assembly !
BTW: as told in advance by the (I would say 'good-old' but he's really youngster...) SandipG, welcome in the THHB [^], [^]!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks Pallini and Stuart,
For the first solution I already knew the static trick but not the template one
For the second..actually I had already used it developing a vst long time ago but I forgot
I used the float since in vst 2.4 the processReplacing function manages float data and it's mandatory to implement it..anyway in the end I followed your advise and used vectors!
Thanks again!!
|
|
|
|
|
Hello all,
I am new to MFC. I know how to create dialogbox by adding the new resource into the resource file. But i want to create DialogBox at runtime without adding it into the Resource.rc file. After creating dialogbox, i have to add Edit control, List Box over that dialog box.
How can i do this?
Thanks in advance.
|
|
|
|
|
Check this[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I would also recommend reading this post:
http://blogs.msdn.com/oldnewthing/archive/2005/04/29/412577.aspx[^]
and some previous ones.
Heck, I recommend reading every single one of his blog posts - you'll learn about lots of things you should and should not be doing.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Thanks for ur reply and suggesting me the link.
I read this post, but it is hard to understand for me, because i am new to MFC.
Please suggest the simplest way with example for creating dialog box without adding dialog resource into the resource.rc file.
|
|
|
|
|
Abhijit D. Babar wrote: because i am new to MFC
This is allllll windows stuff - MFC hardly comes in at all.
Abhijit D. Babar wrote: Please suggest the simplest way
There is no simple way - that's one of the reasons we use templates.
Abhijit D. Babar wrote: with example
Read a few months of the blog before the article I point you at - he builds up from very small examples to large complex ones. I could not write a better one - especially here on the fly.
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|