|
int s are generally 16-bits in DOS, but 32-bits in Windows. If you want 32-bit, use a long . If you want 16-bits, use a short - these are meant to be guaranteed between different compilers.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
|
The C++ standard states that a long is 4 bytes and a short is 2 bytes. An int is defined by the size of the standard machine word for the architecture you're compiling for - 32 bits for Windows and 16-bits for DOS (unless you're using a 32-bit DOS extender such as DOS4GW).
Note that the size of a byte is not defined (other than to say it must be at least 8 bits), so a short may not actually be 16 bits, although I've never seen a situation where it is different.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
Yeah, longs in .NET are 64-bits by definition.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
Heya
I'm using DiLascia's CPictureCtrl in an MFC application, which works quite nicely. CPictureCtrl is essentially a wrapper around IPicture. Also, I use the gd library in my program. The dream of my sleepless nights would be to update the image displayed in the CPictureCtrl with text put into it through the gd functions. Hence, I'd need the picture to be stored in memory (which it is, inside the CPictureCtrl object) and then manipulate or replace it using gd. Any idea how to put those ends together?
Cheers
Robert
|
|
|
|
|
Hello,
Is it legal to 'delete' single elements of an array that was allocated all at once with 'new Array[Count]' ??
I want to allocate an array of stuff as in 'pArray = new Type[5];'
But I want to de-allocate each element one at a time as in:
for ( a = 0; a < Count; a ++ )
delete pArray[a];
It is giving me ASSERT failures in the C runtime, so I'm thinking that this may not be allowed.
Thanks,
Rich
|
|
|
|
|
What's your reason for wanting to do so?
|
|
|
|
|
Hi, thanks for your response. I was having a brain-lock.
Rich
|
|
|
|
|
You're allocating and deleting different things. So no, generally you can't do this.
But why would you want to do so anyway? Is your array an array of pointers? If so, make sure you do a new on each element of the array, as well as the whole array.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
You're absolutely right. It is not an array of pointers, so when I say "delete Array[a];" I'm telling it to delete the actual instance, rather than the pointer to that instance.
So I wonder why it did not give me a compiler error?
Thanks so much,
Rich
|
|
|
|
|
Don't do that. If you need to construct/destruct individual objects, then a C-style array is the wrong thing to use.
If you could destruct individual members of an array, think what would happen when you later delete the array? The runtime will try to destruct the objects again.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi Mike,
Thank you for your response. I will have to redesign that part of the program to do it in a different way.
Rich
|
|
|
|
|
Troposphere wrote: for ( a = 0; a < Count; a ++ ) delete pArray[a];
You don't need to delete Individual memory...
you can simply delete all memory allocated to the array in one go :-
delete [] pArray
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi all
I am having a problem with opening file for the second time. Below is the function that I wrote.
- cpHeader returns a portion of a string taken from the file
example: the file contains string "abcdefghi jklmn opqrstuvwxyz"
after some manipulations, cpHeader returns "n opqrstuvwxyz" (char*)
- cpTemp is supposedly taking in the rest of the string to process it further.
However, for the time being, it is only a dummy function, doing nothing
The problem occurs after I read a file once. Then, if I want to read another file (either it's the same or different), fileptr always returns NULL. And I received error message as "efghi jklmn opqrstuvwxyz" (not "File open error") . I can't think of any possible reason why this error occur. Or, what is the relationship between the string manipulations and the fopen operation?
It would be very great if anybody could help me with this matter. Thanks!
void convertAndPost(AnsiString filename)
{
FILE *fileptr = NULL;
char *file = filename.c_str();
fileptr = fopen(file, "rt");
if(fileptr == NULL)
{
MessageBox(NULL,"File Open Error",NULL,0);
exit(0);
}
else
{
char* start = cpHeader(fileptr);
cpTemp(start, fileptr);
}
fclose(fileptr);
}
- Sharing information is the best way to advance together -
|
|
|
|
|
kittymew wrote: And I received error message as "efghi jklmn opqrstuvwxyz" (not "File open error") . I can't think of any possible reason why this error occur. Or, what is the relationship between the string manipulations and the fopen operation?
This clearly means, that cpTemp is still involved in the file operations, and you have already returned from the method and close the file pointer even before the file operations have been completed, check out the code in cpTemp, are you returning the command back to convertAdnpost() before the file operations have been completed?
|
|
|
|
|
I have it broken into 3 source files, here is the code:
#include "cstring"<br />
#include "hugeint.h"<br />
<br />
HugeInt::HugeInt( long val )<br />
{<br />
int i; <br />
<br />
for ( i = 0; i <= 29; i++ )<br />
integer [i] = 0;
<br />
for ( i = 29; val != 0 && i >= 0; i-- ) <br />
{<br />
integer[i] = val % 10;<br />
val /= 10;<br />
}<br />
}<br />
HugeInt::HugeInt( char *string )<br />
{<br />
int i, j;<br />
<br />
for ( i = 0; i <= 29; i++ )<br />
integer[i] = 0;<br />
<br />
for ( i = 30 - strlen( string ), j = 0; i <= 29; i++, j++ )<br />
if (isdigit( string[j] ))<br />
integer[i] = string[j] - '0';<br />
}<br />
HugeInt HugeInt::operator+( HugeInt &op2 )<br />
{<br />
HugeInt temp;<br />
int carry = 0;<br />
<br />
for ( int i = 29; i >= 0; i-- ) <br />
{<br />
temp.integer[i] = integer[i] + <br />
op2.integer[i] + carry;<br />
<br />
if ( temp.integer[i] > 9 ) {<br />
temp.integer[i] %= 10;<br />
carry = 1;<br />
}<br />
else<br />
carry = 0;<br />
}<br />
<br />
return temp;<br />
}<br />
HugeInt HugeInt::operator+( int op2 )<br />
{ return *this + HugeInt( op2 ); }<br />
<br />
HugeInt HugeInt::operator+( char *op2 )<br />
{ return *this + HugeInt( op2 ); }<br />
<br />
ofstream& operator << ( ofstream &output, HugeInt &num )<br />
{<br />
int i;<br />
<br />
for ( i = 0; ( num.integer[i] == 0 ) && ( i <= 29 ); i++ );
if ( i == 30 )<br />
output << 0;<br />
else<br />
for ( ; i <= 29; i++ )<br />
output << num.integer[i];<br />
<br />
return output;<br />
}<br />
<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
class HugeInt {<br />
<br />
public:<br />
short integer[30];<br />
HugeInt();
HugeInt( long int );
HugeInt( const char * );
HugeInt operator+( HugeInt );
void operator=( HugeInt );
void print( ofstream& );
};<br />
<br />
#include <fstream>
#include "hugeint.h"<br />
<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
HugeInt n1(7654321), n2(7891234),<br />
n3("99999999999999999999999999999"), n4("1"), n5;<br />
<br />
fstream fout;<br />
fout.open("file.txt");<br />
<br />
fout << "n1 is ";<br />
n1.print(fout);<br />
fout << endl;<br />
fout << "n2 is ";<br />
n2.print(fout);<br />
fout << endl;<br />
fout << "n3 is ";<br />
n3.print(fout);<br />
fout << endl;<br />
fout << "n4 is ";<br />
n4.print(fout);<br />
fout << endl;<br />
fout << "n5 is ";<br />
n5.print(fout);<br />
fout << endl;<br />
<br />
n5 = n1 + n2;<br />
n1.print(fout);<br />
fout << " + ";<br />
n2.print(fout);<br />
fout << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
n5 = n3 + n4;<br />
n3.print(fout);<br />
fout << " + ";<br />
n4.print(fout);<br />
fout << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
n5 = n1 + 9;<br />
n1.print(fout);<br />
fout << " + " << 9 << " = ";<br />
n5.print(fout);<br />
fout << endl; << endl;<br />
<br />
n5 = n2 + "10000";<br />
n2.print(fout);<br />
fout << " + " << "10000" << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
fout.close();<br />
return 0;<br />
} <br />
<br />
My main error is 'HugeInt::print' : cannot convert parameter 1 from 'std::fstream' to 'std::ofsteam &'
but there may be more errors than this. Thanks for any help you could give!
-- modified at 14:41 Sunday 12th February, 2006
|
|
|
|
|
HugeInt::print(..) code is missing?!
|
|
|
|
|
hmmm that does make sense... I dont even have a HugeInt::print why would it give me an error pertaining to that? Only thing I have about print is void print(&ofstream);
Thanks for the reply, still need help
|
|
|
|
|
Hey all.
I'm working on a shell namespace extension that needs to provide access to files over the Internet.
My problem is that Explorer's UI freezes when the user attempts to drag files out of it. I've already implemented IAsyncOperation in my IDataObject, but that only seems to allow the drop *target* to run on a background thread.
I provide files through the CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS combo wrapped in IStream interfaces, and Explorer always calls IStream::Read() on the same thread as the rest of the UI, thus freezing everything. I'd love to either be able to return E_PENDING or something similar, or simply get called on a background thread.
For the record, I set SFGAO_ISSLOW for all items while in IShellFolder::GetAttributesOf(), but it doesn't help.
I'm slowly running out of ideas here. The interface is frozen solid while in IStream::Read(). It doesn't even redraw.
There's got to be a solution to this, that I'm just not seeing. I've been looking into async monikers, but all I managed to do was get my brain into a knot, since nowhere does the shell namespace documentation reference them, so I'm assuming there might be another way.
Any help/suggestion will be greatly appreciated.
|
|
|
|
|
Hi guys
I want to know is there any way to fade out text in CStatic. Any idea or concept??
thanks
|
|
|
|
|
If I was making a CStatic control to do this, I would handle the reflected
WM_CTLCOLORSTATIC message to use custom colours, and then create a timer
which updated the colour and invalidate the static control.
That should give you enough to get started with!
Iain
|
|
|
|
|
Hi Iain
thanks a lot for reply.
well is there a way to fade out the text with dissolve effect.
thanks
۞It is on our failures that we base a new and different and better success.
|
|
|
|