473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

question on valarray

Just a few lines:

1: valarray<int> t(0, 10);
2: for (int i = 0; i < 10; ++i)
3: t[i] = i;
4: valarray<int> t2 = t[slice(0, 3, 1)];

Line 4 causes a core dump with g++. Why?

Besides, if I change line 4 to the following:
valarray<int> t2 = (valarray<int>) t[slice(0, 3, 1)];
It works with Visual C++ but not with g++ (Compilation error. I forgot what
the message was). Is there any way to fix it?

Thanks.

Regards,
Milan.
Jul 22 '05 #1
1 1289
On Tue, 20 Jan 2004 23:34:11 +0800, "Milan" <so*****@internet.com>
wrote:
Just a few lines:

1: valarray<int> t(0, 10);
valarray<int> t(10); //since you initialize below
2: for (int i = 0; i < 10; ++i)
3: t[i] = i;
4: valarray<int> t2 = t[slice(0, 3, 1)];

Line 4 causes a core dump with g++. Why?
Compiler bug? The code is fine, and works for me on GCC 3.2.

Besides, if I change line 4 to the following:
valarray<int> t2 = (valarray<int>) t[slice(0, 3, 1)];
You shouldn't use C-style casts in C++ usually. In any case, the cast
isn't necessary.
It works with Visual C++ but not with g++ (Compilation error. I forgot what
the message was). Is there any way to fix it?


Upgrade? What version are you using?

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Prune Tracy | last post by:
I have a question about assignment of slices of valarrays. I want to assign one general slice of a valarray to another. It seems the only way is to use the static_cast syntax, but this seems to...
6
by: Steven T. Hatton | last post by:
I bought Josuttis's book on the repeated recommendations of people in this newsgroup. http://www.josuttis.com/libbook/ One of the first things I looked up was the std::valarray<>. And what I...
3
by: Peter | last post by:
Hi everybody, I am unfortunately stuck with a probably very simple problem. I made a class called Particle with a valarray (STL) as a class member. The code for the class goes like this: ...
2
by: Michael Hopkins | last post by:
Hi all I have a subclass of valarray<T> thus template <typename T> class uo_val : public std::valarray<T> { public: uo_val ( ) : std::valarray<T>() {} uo_val (const int sz ) :...
1
by: Dack | last post by:
Hi, I want to track memory leaks in my application (that is using <valarray>). I used the following code: #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> But then, when I...
9
by: Jim | last post by:
Hi, I want to declare that that a valarray of a certain name exist at the beginning of some code, but I can't instatiate it until I've read in some parameters later on in a for loop i.e. int...
3
by: Alex Howlett | last post by:
Stroustrup page 663 says this: valarray<floatv1 (1000); // 1000 elements with value float()==0.0F But when I run this program: -------------------------------------- #include <valarray>...
2
by: john | last post by:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is mentioned: "valarray operator-() const; // result= -v for every element // similarly: +, ~, !" I checked the web and...
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.