By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

stack corruption

P: n/a
Ok here is a short description of what i am doing. I need to program
a dll for use by another program. the dll compiles fine but when i
call it from another program i get a stack corruption of the array in
the gamma section of the dll. so below i will post the code for in
order:

my dll header
my dll cpp

my testprogram header
my testprogram cpp

ANY help on this would be fantastic.
my dll header

#ifndef EICKEMEIER_INCLUDE
#define EICKEMEIER_INCLUDE
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a);
#endif

my dll cpp

#include <math.h>
#include <iostream>
#include <stdexcept>
using namespace std;
long double gammafcn( double x)
{
long double tmp, ser, stp, temp;
int j;
long double cof[6];

stp = 2.50662827465;

cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;

x = x - 1;
tmp = x + 5.5;
tmp = (x + 0.5) * log(tmp) - tmp;
ser = 1;

for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
}

temp =(exp(tmp + log(stp * ser)));
return temp;
}
double Eickemeier(int x, int y, double xc, double yc, double volc,
double sig, double del, double zu, double zo, double b, double a)
{
double Rz, rx, fr, eick, temp;
long double gamma;

Rz = pow(zu * zo , 0.5) * (1 / tan(b * 3.14159265 / 180));
rx = pow((pow((x - xc) , 2) + pow((y - yc) , 2)), 0.5);

temp =2 / del;
gamma = gammafcn(temp);

fr = (sig * del) / (pow(2 * 3.14159265 , (1 - (2 / del))) *
pow(Rz , 2) * gamma) * exp(-3.14159265 * pow(sig , (del /
2)) * pow(rx / Rz , del));

eick = a * fr * volc;

return (eick);
}
my testprogram header

#pragma once

#include "resource.h"
my testprogram cpp

#include "eickDll.h"
#include "stdafx.h"
#include "testfile.h"
#include <iostream>

double Eickemeier();
using namespace std;

int main()
{
double x;

x = Eickemeier(0, 0, 0, 0, 2000000, 1, 2, 505, 5, 30, 1);

cout << x;
cin >x;

return 0;
}

Jun 7 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
if***********@gmail.com wrote:
[..]
long double cof[6];
[..]
cof[1] = 76.18009173;
cof[2] = -86.50532033;
cof[3] = 24.01409822;
cof[4] = -1.231739516;
cof[5] = 0.00120858003;
cof[6] = -0.00000536382;
In C++ an array of 6 elements has indices from 0 through 5.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 7 '07 #2

P: n/a
Changed the indecies (i feel silly for missing that) but the same
problem persists.

Jun 7 '07 #3

P: n/a
i also changed the for loop accordingly. the error crops up before the
gamma function is even called.

Jun 7 '07 #4

P: n/a
if***********@gmail.com wrote:
....
>
long double gammafcn( double x)
{
.....
>
for (j=1; j<7; j++)
{
x = x + 1;
ser = ser + cof[j] / x;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Still have a problem here.
}

temp =(exp(tmp + log(stp * ser)));
return temp;
}
Jun 7 '07 #5

P: n/a
if***********@gmail.com wrote:
i also changed the for loop accordingly. the error crops up before the
gamma function is even called.
I believe that's answered in FAQ 5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 7 '07 #6

P: n/a
Apologies for not following proper posting etiquette.

compiler name, version number, operating system.
visual studio .net 2003 sp1 windows xp

libraries, exact compiler and linker options.
libs = math.h, iostream,
compiler is visual studio 2003
linker options = visual studio defualt

exact messages received.
run time check failure #2 - Stack around the variable of 'cof' was
corrupted

also i am having trouble finding the error in my for statement that
Gianni Mariani mentioned. I have never worked down at the stack level
before so please forgive my slow pace at picking things up.

Jun 8 '07 #7

P: n/a
if***********@gmail.com wrote:
Apologies for not following proper posting etiquette.

compiler name, version number, operating system.
visual studio .net 2003 sp1 windows xp
Only matters if you seek a confirmation that it's a bug in that
compiler. We generally don't discuss compilers here.
libraries, exact compiler and linker options.
libs = math.h, iostream,
Those are not "libs". They are _headers_. Options don't matter.
compiler is visual studio 2003
linker options = visual studio defualt

exact messages received.
run time check failure #2 - Stack around the variable of 'cof' was
corrupted
That's not a message from the compiler. That's from your execution
environment. Please learn to debug your program.
also i am having trouble finding the error in my for statement that
Gianni Mariani mentioned. I have never worked down at the stack level
before so please forgive my slow pace at picking things up.
You don't need to "work down at the stack level" if you write correct
C++ code. Again, post your *code*, and we will try to help. If you
are confused about how and what to post, try looking at other people's
posts. See what they posted, what information they provided, and
follow any good example you'll find.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.