473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

stack corruption

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
7 2134
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
Changed the indecies (i feel silly for missing that) but the same
problem persists.

Jun 7 '07 #3
i also changed the for loop accordingly. the error crops up before the
gamma function is even called.

Jun 7 '07 #4
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ilia Poliakov | last post by:
I have a static function in the class like this: class A { static void f1() } void A::f1() { .....
3
by: harry | last post by:
Hi all I am putting a code snippet #include "stdio.h" #include "conio.h" struct base{ int i; char c; };
18
by: Dev | last post by:
I'm working with some IBM sponsored C APIs to interface with a corporate legacy system, and it seems that I'm getting some stack corruption after any API call. I believe the APIs were designed...
1
by: Humber Consumer | last post by:
I have a simple question. I have following piece of code in a sample MFC application: void CSampleAppDlg::OnButton1() { try { char e; ...
14
by: Peter Schmitz | last post by:
Hi, I'm currently developing an application that includes an implementation of the well-known Boyer- Moore algorithm. For this, I use the implementation of Thierry Lecrq from...
6
by: Tony | last post by:
Is there any value to pursuing program designs that mimimize the mainline call stack? For example, within main() I could code up something like: while(GetMsg(m)) DispatchMsg(m); instead of...
13
by: deepak | last post by:
Hi In the following function how the memory 'll be allocated. 1) Will it allocate memory for all the char's together or allocate for first char. then for int then for float and after this only...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.