|
AFAIK no.
Either make the array one element bigger and ignore element zero; or subtract one from every index.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
timbk wrote: hello, is there any way to declare an indexed array in base one on VC++?
thanks.
You can even use ten-based array: just remember to subract 10 to the index before using it inside the [] operator...
[added]
Hi, Mr.Univoter. Don't you like 10 -based arrays, do you?
[/added]
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]
modified on Wednesday, November 11, 2009 3:04 AM
|
|
|
|
|
thanks, how can i do to declare a ten based array?
|
|
|
|
|
timbk wrote: thanks, how can i do to declare a ten based array?
Do you understand irony music, Yoko?
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]
|
|
|
|
|
ohh, sorry i'm learning english and VC++, and i don't study " how to understand jokes".
|
|
|
|
|
I'm sorry for you.
C/C++ arrays are zero based.
While there's nothing wrong in liking better one-based arrays, it is wiser remaining stuck with zero-based ones, because:
- You need extra work to make your arrays alive (extra work is generally bad)
- Most people use the opposite convention: that means you have to adapt your data to any time you've to deal with other people code, like libraries, etc..
Neverthless, there are few examples of consistently used one-based arrays, for instance, all "Numerical Recipes" book source code uses it (the authors simply ignore array item 0 ).
Like all 'alien' conventions it's a bit difficult to grasp immediately, but after some experience with, becomes 'natural'.
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]
|
|
|
|
|
As they said, no, but you could write your own 1 based array class in C++ and overload the [] operator and whatever else is necessary to do the index adjustment for you.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
thanks, well i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive, we starts count in one, i think that the easy way is make the array one element bigger but when you have many arrays is a waste of memo, so i would try with your seggest.
|
|
|
|
|
If you search around, you probably can find example code. I think I once saw it as an example in a C++ book.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
timbk wrote: i was trying to make the app more easy to follow, because 0 based arrays are not so intuitive
you will confuse any C/C++ programmer who has to maintain the code, if you start doing things like that.
|
|
|
|
|
How is that any different than most of the code I had to maintain in my career?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi
I have Unicode application which uses "wistream" to read a unicode file. But there is a ANSI file I need to read also.
Is there a way to convert "wistream" to "istream"?
Thanks,
|
|
|
|
|
Use an istream object to read the ANSI file.
istream will work irrespective of whether the application in unicode or not.
|
|
|
|
|
I have "wistream" instance like
wistream wis;
I have another function which parameter data type is "istream". So how to convert "wis" to "istream" object?
Thanks
|
|
|
|
|
Create a new istream instance.
|
|
|
|
|
I'm using g++ version 4.4.1 in Ubuntu and I am trying to use the SSE3 intrinsic for the HADDPS instruction. I have included the header file:
xmmintrin.h,
and I have in my code:
num3 = _mm_hadd_ps(num3, num3);
where num3 is of type __m128.
Unfortunately, when I go to compile, I get the error message:
error: ‘_mm_hadd_ps’ was not declared in this scope
Other SSE intrinsics, such as _mm_setzero_p or _mm_mul_ps, work fine. Those are SSE or SSE2 intrinsics though...
Does anyone know if g++ supports the _mm_hadd_ps intrinsic? Or maybe there is another intrinsic for this instruction? Any help is much appreciated.
|
|
|
|
|
I found it. In g++ the _mm_hadd_ps intrinsic is found in
<pmmintrin.h>
|
|
|
|
|
the suspense is killing me.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Ooops. It didn't paste the header file name! The name is:
pmmintrin.h
|
|
|
|
|
In my CSocket client program, when I repeatedly relogon from one client, I see "Socket Notification Sink" exception.
I read some posts on the forum about this error, which said: dummy window and something else - anyway, it is bad design of CSocket.
In my case, I guess the exception is around function CSocket::Close(), CSockt::Connect() and CSocket::Send() for sending first message. I also guess the exception is caused by if CSocket is not ready for use.
I used try-catch, but the exception can not be catched.
Do you have any comments to avoid the exception?
BTW: do raw socekt functions have the problem?
|
|
|
|
|
You could always use Winsock functions directly, and avoid CSocket altogether.
|
|
|
|
|
Have you noticed that he's just posted the same thing below? He's given it one hours time, and after not responding to any queries that David asked, he deleted his previous query and started a new thread (same title, same contents, no more information).
Ignore that idiot.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
|
includeh10 wrote: ...anyway, it is bad design of CSocket.
Are you implying that the problem could not be in your code?
includeh10 wrote: Do you have any comments to avoid the exception?
Yes. Fix the code that is causing the exception. Now before you get your undies all in a bunch and whine that my suggestion is not helpful and ban me from commenting further, think about the question you've asked and if you really think you've provided enough information for us to be helpful.
includeh10 wrote: BTW: do raw socekt functions have the problem?
Have you tried using them to narrow the problem down?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hey guys,
So I have a directive like this:
#define NOOB_ME 1
Now let's say I have the following char array:
char buf[] = "NOOB_ME"
I want to store the char array in an int variable so that when I do a printf I should get a 1 (as per the value of the directive). Example:
int num = buf(I know this assignment is incorrect, but I want it to be the same as int num = NOOB_ME which is valid and produces an output 1)
Is there any way to get this done?
modified on Wednesday, November 4, 2009 3:32 PM
|
|
|
|