|
No. Both are Turning Complete, and therefore anything you can write in one you can in the other.
However there are strong reasons to use one over the other anyway. There are many things that are easier to write in C than C++, and vise versa. (C++ is easier for large teams/projects, C is easier for direct to hardware performance counts programs. Even this is a gross over generalization and you can find exceptions)
Turing complete is named for Alan Turing who proved sometime ago (1930s? +-20 years) that any program that you can impliment in one language can be implimented in any other. The simplest turning complete language supports one command: subtract branch on zero. (don't ask me who to prove that)
|
|
|
|
|
Why is C easier for direct hardware programs?
|
|
|
|
|
simpler. When directly accessing hardware you need to force some things to be in a specific memory location. You often have limited memory you can use (ISA devices cannot access memory over 16 megabytes, not a factor now, but it was not long ago, and may be again when the limits of 32 bit PCI is reached). The base OS is normally written in C or assembly, so you have to jump in and out of C often. C++ intorduces overhead that isn't needed.
In general, even though these limits are not hard to overcome in C++, the programs that directly access hardware are so small that C++ gives no advantage.
You can do this in C++, and it has been done. However there is no real advantage.
I'm only talking about the lowest level device drivers. If you are not messing with registers you are above this point.
|
|
|
|
|
Henry miller wrote:
Turing complete is named for Alan Turing who proved sometime ago (1930s? +-20 years) that any program that you can impliment in one language can be implimented in any other. The simplest turning complete language supports one command: subtract branch on zero.
Are you referring to the Turing machine, that was introduced in 1936? In all my years of studying this, I've never heard your explanation. In short, a Turing-complete problem is one that can only be solved by a Turing machine, which is an abstract representation of a computing device, or a Turing-Equivalent system. A Turing-Equivalent system is equivalent to a Turing machine.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yes. any machine that can solve a (non-trivial) problem that a turning machine can sovle, can sovle any other problem a turning machine can solve. In the real world we have finate turning machines, and assume sufficant length, otherwise the theory applies. I'm too far out of school to put it in more detail anymore.
|
|
|
|
|
Hello
How to copy the content of the client device context to Memory Device context?
I want the complete drawing on the view to be stored as Bitmap file. FOr this i want Memory Device context.
Further there are issues such as does it affects that when i initialise my memory Device Context, i.e. before complete drawing or after complete drawing.
Sandeep
Leave your mark wherever you go
|
|
|
|
|
What about the function BitBlt, with the SRCCOPY flag. That copys from one DC to another?
|
|
|
|
|
Hi all,
My List control displays Timestamp along with date (15/6/2004 12:02:02 AM)..
My code to sort this data is....
int CALLBACK CBoseDayalaNewListCtrl::CompareDates(LPARAM lParam1, LPARAM lParam2, LPARAM lSortParam)
{
CString str1 = *((CString*)(((ItemData*)lParam1)->dwItemData));
CString str2 = *((CString*)(((ItemData*)lParam2)->dwItemData));
COleDateTime odtTime1;
COleDateTime odtTime2;
BOOL fSortAscending = BOOL(lSortParam);
double dblResult = 0.0;
odtTime1.ParseDateTime( str1, LOCALE_NOUSEROVERRIDE );
odtTime2.ParseDateTime( str2, LOCALE_NOUSEROVERRIDE );
if(fSortAscending)
dblResult = odtTime1 - odtTime2;
else
dblResult = odtTime2 - odtTime1;
return ( ( 0.0 < dblResult ) ? 1 : ( ( 0.0 == dblResult ) ? 0 : -1 ) );
}
....and this doesn't work fine it seems...can anybody gimme more efficient code so that I will be so grateful...
thanks in advance.
MrBoseDayala
|
|
|
|
|
What do mean by "it doesn't work fine"? Does it not work at all or is it slow and inefficient?
If it's inefficent, maybe store pointers to the COleDateTime in the data address of the items, rather than CString pointers that you need to convert every time you do a sort.
Another option would be that at the time you are inserting items into the listctrl, the dwData(param) could be a
time_t object. This is just a typedef'd long. That way you don't need to allocate memory for CStrings or COleDateTime objects, and stil do the comparisons.
|
|
|
|
|
it is not working efficient...I have send the picture to u.please have a look..
BoseDayala
|
|
|
|
|
Hi Bose,
the only thing I can see that could be incorrect, is that the ItemData that you are pointing to, has the incorrect values in it. I would debug through it, and step through and check the value (dates/time/strings) that you are using.
I did a quick test, and used pointers to CStrings as the lParam in each item, and used almost the same function as you in the comparison. It seemed to work fine. just remember that I didn't have a ItemData structure, I used pointers to CStrings that held the date/times.
Jubjub
|
|
|
|
|
Mr Bose Dayala wrote:
it is not working efficient
So it is working, just not very fast?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
efficient means...some dates are not being sorted properly...
ThomasKennedyBose
|
|
|
|
|
A sorting algorithm either sorts or it doesn't. There is no "some."
How are you adding items to the list control? What parameters are you calling SetItemData() with? The 0.0 == dblResult comparison is obviously wrong. You should never compare double or float variables in this fashion. Hopefully you meant for the comparision to look like return ((0.0 < dblResult) ? 1 : ((dblResult < 0.0) ? -1 : 0)) , but this will still lead to undesirable results, because dblResult will always be greater than or less than 0. A more elegant solution would be:
int CALLBACK CBoseDayalaNewListCtrl::CompareDates(LPARAM lParam1, LPARAM lParam2, LPARAM lSortParam)
{
CString *str1 = (CString*)(((ItemData*)lParam1)->dwItemData);
CString *str2 = (CString*)(((ItemData*)lParam2)->dwItemData);
CString *temp;
COleDateTime odtTime1;
COleDateTime odtTime2;
BOOL fSortAscending = BOOL(lSortParam);
int nResult = 0;
if (fSortAscending)
{
temp = str1;
str1 = str2;
str2 = temp;
}
TRACE("Comparing %s to %s\n", str1.Format("%c"), str2.Format("%c"));
odtTime1.ParseDateTime( str1, LOCALE_NOUSEROVERRIDE );
odtTime2.ParseDateTime( str2, LOCALE_NOUSEROVERRIDE );
if (odtTime1 < odtTime2)
nResult = -1;
else
nResult = 1;
return nResult;
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi all ,
I want to get the pointer of the document and traverse thr u all views of the document and bring into active state one of those views..How can i do it?I tried using GetFirstDocTemplatePosition() in the CWinApp derived class but its giving me runtime error...What to do??Do help me
|
|
|
|
|
Did you try :
CWinApp *pApp = AfxGetApp();
if(pApp)
{
POSITION pos = pApp->GetFirstDocTemplatePosition();
while(pos != NULL)
{
CDocTemplate *pDocTemplate = pApp->GetNextDocTemplate(pos);
if(pDocTemplate )
{
POSITION pos2 = pDocTemplate->GetFirstDocPosition();
while(pos2 != NULL)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(pos2);
}
}
}
}
the other option, is if you are in a view already,
you can just called GetDocument
CDocument *pDoc = GetDocument();
|
|
|
|
|
Hi,
Thanks for ur interest in helping me.I tried the code u have given but its giving runtime Assertion Errors.Can u send me any working sample which uses these functions?
Thanks
|
|
|
|
|
I don't know if it would work, but you can try searching on:
EnumChildWindows, EnumWindows, ...
these can give you the handle you need.
Note: this will cycle through all windows on your desktop, you'll have to figure out which is which.
Good luck,
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
How to get memory info of a process not using PSAPI
I want to get memory information of a process, include stack, heap, all memory the process used.
My Program must support Win98, Win2000, WinXp,
So I can't depend on PSAPI to do these.
thanks...
|
|
|
|
|
You mean like ReadProcessMemory() , and Process32First() /Process32Next() ? If so, see if this article is of any help.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
use CreateWin32SnapShot() api function a
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
How to improve on Genetic Algorithms by using Fusion operator?
Change the codes please, thank you!
My English is poor
Codes:
#include<iostream.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#define maxgen 500
#define POPSIZE 500
#define PopSize 100
#define kind -2
#define NVARS 9
#define Umin -1
#define Umax 1
#define Cmax 100
#define Cmin 0
double pxover= 0.75;
double pmutation = 0.2;
int gen,j;
int best_val = 0;
double m_A0,m_B0,m_A1,m_B1,m_A2,m_B2;
double A0,A1,A2,A3,A4,B1,B2,B3,B4;
long double x[100],y[100],z[100],a[100];
struct Individual{
double chrom[NVARS];
long double value;
long double fitness;
};
struct Individual population[POPSIZE];
struct Individual bestindividual;
struct Individual currentbest;
#define rd(i) (rand()%(int)(i))
#define rdf() ((float)rd(1000)/(1000.0))
void produce()
{
srand((unsigned)time(NULL));
for(int i=0;i<PopSize;i++)
{
population[i].chrom[0] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[1] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[2] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[3] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[4] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[5] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[6] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[7] =m_A0 +rdf()*(m_B0-m_A0);
population[i].chrom[8] =m_A0 +rdf()*(m_B0-m_A0);
}
for(int j=0;j<100;j++)
{
x[j]=m_A0+rdf()*(m_B0-m_A0);
y[j]=x[j];
}
}
void evaluation()
{
long double l;
l=(m_B0-m_A0)/2;
for(int i=0;i<PopSize;i++){
A0=population[i].chrom[0];
A1=population[i].chrom[1];
B1=population[i].chrom[2];
A2=population[i].chrom[3];
B2=population[i].chrom[4];
A3=population[i].chrom[5];
B3=population[i].chrom[6];
A4=population[i].chrom[7];
B4=population[i].chrom[8];
for(j=0;j<100;j++)
{
z[j]=A0/2+A1*cos(atan(1)*4*x[j]/l)+B1*sin(atan(1)*4*x[j]/l)+A2*cos(atan(1)*8*x[j]/l)+B2*sin(atan(1)*8*x[j]/l)+A3*cos(atan(1)*12*x[j]/l)+B3*sin(atan(1)*12*x[j]/l)+A4*cos(atan(1)*16*x[j]/l)+B4*sin(atan(1)*16*x[j]/l);
//z[j]=A0/2+A1*cos((atan(1)*4*x[j])/l)+B1*sin((atan(1)*4*x[j])/l)+A2*cos((atan(1)*8*x[j])/l)+B2*sin((atan(1)*8*x[j])/l)+A3*cos((atan(1)*12*x[j])/l)+B3*sin((atan(1)*12*x[j])/l)+A4*cos((atan(1)*16*x[j])/l)+B4*sin((atan(1)*16*x[j])/l);
}
for(j=0;j<100;j++)
{
a[j]=0.5*(z[j]-y[j])*(z[j]-y[j]);
population[i].value+=a[j];
}
}
}
void fitness()
{
for(int i=0;i<PopSize;i++)
{
if(kind>0)
{
population[i].fitness = population[i].value-Cmin;
}
else
{
population[i].fitness = Cmax - population[i].value;
}
}
}
void findbest()
{
bestindividual=population[0];
for(int i=1;i<PopSize;i++)
{
if(population[i].fitness > bestindividual.fitness)
{
bestindividual = population[i];
best_val = i;
}
}
if(gen==0)
{
currentbest = bestindividual;
}
else if( currentbest.fitness<bestindividual.fitness)
{
currentbest = bestindividual;
}
}
void select()
{
double cfitness[POPSIZE];
double sum = 0;
double p;
int index=0;
struct Individual newpopulation[POPSIZE];
for(int i=0;i<PopSize;i++)
{
sum +=population[i].fitness;
}
for(i =0;i<PopSize;i++)
{
cfitness[i] = population[i].fitness / sum;
}
for(i=1;i<PopSize;i++)
{
cfitness[i] = cfitness[i-1] + cfitness[i];
}
srand((unsigned)time(NULL));
for(i=0;i<PopSize;i++)
{
p = rdf();
while(p > cfitness[index])
{
index++;
}
newpopulation[i] = population[index];
}
for(i =0;i<PopSize;i++)
{
population[i] = newpopulation[i];
}
}
void crossover()
{
int index[POPSIZE];
int point,temp,i=0;
long double p;
struct Individual newpopulation[POPSIZE];
for(i=0;i<PopSize;i++)
{
index[i] = i;
newpopulation[i] = population[i];
}
srand((unsigned)time(NULL));
for(i=0;i<PopSize;i++)
{
point=(int)rand()/1000;
point+=i;
while(point>=PopSize)
{
point/=2;
}
temp = index[i];
index[i] = index[point];
index[point] = temp;
}
while(i<PopSize-1)
{
for(int j=0;j<NVARS;j++)
{
p = rdf();
if(p<pxover)
{
newpopulation[index[i]].chrom[j]= p*population[index[i+1]].chrom[j] + (1-p)*population[index[i]].chrom[j];
newpopulation[index[i+1]].chrom[j]= p*population[index[i]].chrom[j] + (1-p)*population[index[i+1]].chrom[j];
}
}
i=i+2;
}
for(i=0;i<PopSize;i++)
{
population[i] = newpopulation[i];
}
}
void mutate()
{
int p = 2;
double r;
double ytemp;
double temp;
double T;
double a[NVARS],b[NVARS];
srand((unsigned)time(NULL));
for(int i=0;i<POPSIZE;i++)
{
for(int j=0;j<NVARS;j++)
{
a[0]=m_A0;
b[0]=m_B0;
a[1]=m_A1;
b[1]=m_B1;
a[2]=m_A2;
b[2]=m_B2;
r = rdf()-0.5;
if(r<pmutation)
{
if(r<0)
r = -r;
T = 1-population[i].fitness/100;
if(rand()%2==0)
{
ytemp = b[j]- population[i].chrom[j];
temp = ytemp*( 1-pow(r,pow( T,p)));
population[i].chrom[j] = population[i].chrom[j] + temp;
}
else if(rand()%2==1)
{
ytemp = population[i].chrom[j] - a[j];
temp = ytemp*( 1-pow(r,pow( T,p)));
population[i].chrom[j] = population[i].chrom[j] - temp;
}
}
}
}
}
void replace()
{
if(bestindividual.fitness>currentbest.fitness)
{
currentbest = population[best_val];
}
}
void main()
{
m_A0=-atan(1)*4,m_B0=atan(1)*4;
produce();
cout<<"A0="<<A0<<'\n';
cout<<"A1="<<A1<<'\t'<<"B1="<<B1<<'\n';
cout<<"A2="<<A2<<'\t'<<"B2="<<B2<<'\n';
cout<<"A3="<<A3<<'\t'<<"B3="<<B3<<'\n';
cout<<"A4="<<A4<<'\t'<<"B4="<<B4<<'\n';
for(int i=0;i<maxgen;i++)
{
evaluation();
fitness();
findbest();
select();
crossover();
mutate();
replace();
}
cout<<"m_A0="<<m_A0<<'\t'<<"m_B0="<<m_B0<<'\n';
cout<<bestindividual.fitness<<'\n';
cout<<currentbest.value<<'\n';
cout<<"kind="<<kind<<'\n';
//cout<<"A0="<<population[PopSize-1].chrom[0]<<'\n';
//cout<<"A1="<<population[PopSize-1].chrom[1]<<'\t'<<"B1="<<population[PopSize-1].chrom[2]<<'\n';
//cout<<"A2="<<population[PopSize-1].chrom[3]<<'\t'<<"B2="<<population[PopSize-1].chrom[4]<<'\n';
//cout<<"A3="<<population[PopSize-1].chrom[5]<<'\t'<<"B3="<<population[PopSize-1].chrom[6]<<'\n';
//cout<<"A4="<<population[PopSize-1].chrom[7]<<'\t'<<"B4="<<population[PopSize-1].chrom[8]<<'\n';
cout<<"A0="<<A0<<'\n';
cout<<"A1="<<A1<<'\t'<<"B1="<<B1<<'\n';
cout<<"A2="<<A2<<'\t'<<"B2="<<B2<<'\n';
cout<<"A3="<<A3<<'\t'<<"B3="<<B3<<'\n';
cout<<"A4="<<A4<<'\t'<<"B4="<<B4<<'\n';
//for(int j=0;j<100;j++){
// cout<<x[j]<<'\t'<<y[j]<<'\t'<<z[j]<<'\t';
//}
}
|
|
|
|
|
*shrug* Fusion operator? whats that ?
|
|
|
|
|
It's a kind of operator which can prevent the fuction from converging.
|
|
|
|
|
I want to get the rect's area of the MinimizeBox,MaximizeBox,CloseBox,what should I do?
|
|
|
|