473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL vector<float> crash

I put the bare essentials in a console app.

http://home.earthlink.net/~mcolasono/tmp/degub.zip

Opening output.fft and loading it into a vector<float> screws
up, but input1.dat doesn't. It does load the vector, too. It just
craps out when you return to the console, or in a [wx]Windows app,
the message loop. I think it has something to do with the
vector<float> going out of scope and trying to free memory, but
don't know why it would do that. The fft file is 512 floats and I
converted the actual values (which came out of the vector which
crashed, BTW) to test.txt.

I did it in VC++. Maybe another compiler or OS won't have a prob
with it.

I'd appreciate it if someone could try it out and see what happens.

Thanks in advance.
--
Best Regards,
Mike
Jul 23 '05 #1
18 2552
Active8 wrote:
I put the bare essentials in a console app.


Actually, you didn't! This code uses at least one [actually even
unnecessary], environment specific header and I doubt that you
have reduced it to the bare minimum of code exposting the problem.
You are using the wrong convention for headers (you shall not use
angle brackets for your headers; angle brackets are reserved for
the system, i.e. the standard library headers), you pass string
literals as 'char*' (you can't: the type of a string literals is
'char const(&)[n]' which decays to a 'char const*'), and you don't
check for any error codes!

A minimal example typically takes something like 30 lines of code.
In reducing the code to a minimal amount you would normally also
stumble over some thinko...
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #2
"Dietmar Kuehl" <di***********@ yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
you pass string
literals as 'char*' (you can't: the type of a string literals is
'char const(&)[n]' which decays to a 'char const*'


....umm, aren't you forgetting about the compatibility hack that permits a
string literal to decay to char*?
Jul 23 '05 #3
On Tue, 01 Mar 2005 15:56:29 GMT, Andrew Koenig wrote:
"Dietmar Kuehl" <di***********@ yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
you pass string
literals as 'char*' (you can't: the type of a string literals is
'char const(&)[n]' which decays to a 'char const*'


...umm, aren't you forgetting about the compatibility hack that permits a
string literal to decay to char*?


I've seen plenty of code that passes literals that way. I started
the <> includes when I put the files in a separate dir and meant to
change those to quotes. If I've read that <> is reserved for system
files, I forgot, but now I know.

--
Best Regards,
Mike
Jul 23 '05 #4
On 1 Mar 2005 07:41:27 -0800, Dietmar Kuehl wrote:
Active8 wrote:
I put the bare essentials in a console app.
Actually, you didn't! This code uses at least one [actually even
unnecessary], environment specific header and I doubt that you


What file would that be? stdio.h?
have reduced it to the bare minimum of code exposting the problem.
The dspfile class could've been stripped dow a bit, but it's so
small anyway...
You are using the wrong convention for headers (you shall not use
angle brackets for your headers; angle brackets are reserved for
the system, i.e. the standard library headers), you pass string
literals as 'char*' (you can't: the type of a string literals is
'char const(&)[n]' which decays to a 'char const*'), and you don't
check for any error codes!

A minimal example typically takes something like 30 lines of code.
In reducing the code to a minimal amount you would normally also
stumble over some thinko...


Does all that make it so hard to compile and run it?

--
Best Regards,
Mike
Jul 23 '05 #5
Active8 wrote:
What file would that be? stdio.h?
windows.h as used in dspfile.cpp.
The dspfile class could've been stripped dow a bit, but it's so
small anyway...
There are nearly 500 lines. Typical example programs are 20 to 30
lines; rather big examples, commented in the text body of the
message, are typically still less than 100 lines.
Does all that make it so hard to compile and run it?


Yes, it does: it took me about 10 minutes before I got an executable
build. This executable immediately crashed when called without
arguments, i.e. a simple sanity check for the executable already
failed. Contrast this with maybe 40 lines of code I cut and paste
from the browser into a C++ file and which runs mere seconds later!
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #6
Andrew Koenig wrote:
"Dietmar Kuehl" <di***********@ yahoo.com> wrote:
you pass string
literals as 'char*' (you can't: the type of a string literals is
'char const(&)[n]' which decays to a 'char const*'
...umm, aren't you forgetting about the compatibility hack that

permits a string literal to decay to char*?


No, I'm not! Maybe it is just me but I tend to use highest warning
level and remove at least most warnings before even considering to run
the code. This normally catches most problems. Using 'char const*'
instead of 'char*' is a trivial change and does not impose any new
constraints (writing to the string literal is prohibited even if it
declared as 'char*'; only the compiler cannot catch the errors related
to writing to string literals). A similar argument applies to the
things I mentioned. Of course, I can make <> delimited, user-defined
headers to work; it just takes another compilation cycle and editing
the compiler flags but should this really be necessary? Of course, I
can figure out how to call the program from the source rather than by
trying to just run it to see that there is yet another problem lurking.

I don't mind to help others as you are probably well aware of. However,
I generally assume that the others have made a reasonable attempt to
solve their problem first. I cannot see an indication of this here.
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #7
Active8 wrote:
I've seen plenty of code that passes literals that way.


.... and all of this code should be flagged with a warning! It is an
error prone habit since you cannot write to string literals but the
compiler cannot help you by prohiting it, i.e. the error occurs at
run-time. The fact there is plenty of code out there meant that a
deprecated features was added to C++ but no new code shall rely on
this feature!
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.contendix.c om> - Software Development & Consulting

Jul 23 '05 #8
In article <1b************ ****@ID-222894.news.ind ividual.net>,
Active8 <re*********@nd bbm.net> wrote:
Opening output.fft and loading it into a vector<float> screws
up, but input1.dat doesn't.


Your "load_vecto r" function is tremendously unsafe. You resize the
vector based on the leader bytes of the file, but there is no check
during the load if you go off the end. (IME, writing past the end of
the vector is the easiest way to crash.)

Furthermore, your call:
fread(it++, sizeof(vec_type ), 1, m_channel);

is problematic to say the least. "it" is a T::iterator, which is not
guaranteed at all to be a pointer. At least, you should use:

fread(&(*it++), sizeof(vec_type ), 1, m_channel);

And if you're using vector, you could do:

itemCount = vec.size();
fread(&vec[0], sizeof(vec_type ), itemCount, m_channel);

or something like that.
Have you verified that 'output.fft' has the right amount of data?
--
Mark Ping
em****@soda.CSU A.Berkeley.EDU
Jul 23 '05 #9
> I've seen plenty of code that passes literals that way. I started
the <> includes when I put the files in a separate dir and meant to
change those to quotes. If I've read that <> is reserved for system
files, I forgot, but now I know.


I'd double-check on that.
Jul 23 '05 #10

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

Similar topics

2
11465
by: Pepijn Kenter | last post by:
Dear experts. I have a vector<float> and want to convert that to a vector<double>. I optimistically tried: #include <vector> #include <iostream> using namespace std; int main() {
10
15672
by: bluekite2000 | last post by:
and why doesnt the standard vector have such conversion available?
9
8239
by: richard_lavoie | last post by:
Hi, I have something like this: vector<floatvec1; and I want to cast it, so I use vector vec2<double= static_cast< vector<double(vec1); I always become a error: syntax error before `>' token in that line
0
1659
by: PaperPilot | last post by:
While trying to copy data into the vector I get the following error messages: stl_algobase.h:247: error: no match for 'operator*' in '*__result' stl_algobase.h:249: error: no match for 'operator++' in '++__result' __result is the vector's OutputIterator the ecode segement that gives me this problem is: typedef std::vector< float >...
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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 we have to send another system
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.