473,395 Members | 2,437 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,395 software developers and data experts.

mystery code?

I ran across this code from a statistics library. The header
source code was not available.

long double __declspec(naked) poisson_distribution(int k,long
double m)
{
}
long double pdtrl(int k,long double m )
{
long double v;

if( (k < 0) || (m <= 0.0L) )
{
mtherr( "pdtrl", DOMAIN );
return( 0.0L );
}
v = k+1;
return( igamcl( v, m ) );
}

What would be the purpose of "__declspec(naked)" in the signature
of poisson_distribution()? Is this legal C syntax? Why would the
function body be empty?
Feb 18 '06 #1
6 2080

"John Smith" wrote:
I ran across this code from a statistics library. The header source code
was not available.

long double __declspec(naked) poisson_distribution(int k,long double m)
{
}
At least a return statement is missing...
long double pdtrl(int k,long double m )
{
long double v;

if( (k < 0) || (m <= 0.0L) )
{
mtherr( "pdtrl", DOMAIN );
return( 0.0L );
}
v = k+1;
return( igamcl( v, m ) );
}

What would be the purpose of "__declspec(naked)" in the signature of
poisson_distribution()?
from the MSDN:
For functions declared with the naked attribute, the compiler generates code
without prolog and epilog code. You can use this feature to write your own
prolog/epilog code sequences using inline assembler code. Naked functions
are particularly useful in writing virtual device drivers.

http://msdn.microsoft.com/library/de...m/msmod_25.asp
Is this legal C syntax?
__declspec is not C. The rest is OK.
Why would the function body be empty?


mostly to avoid errors or to tell the compiler that an assembler
implementation exists, but in this case it will create new ones...

--
regards
John
Feb 18 '06 #2
John Smith <JS****@mail.net> writes:
What would be the purpose of "__declspec(naked)" in the signature
of poisson_distribution()? Is this legal C syntax?
__declspec is either an extension of a particular C
implementation, or it's the name of a macro. It's not standard
C.
Why would the function body be empty?


Beats me.
--
"In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt." -- Blair P. Houghton
Feb 18 '06 #3

"Ben Pfaff" wrote:
John Smith writes:
What would be the purpose of "__declspec(naked)" in the signature
of poisson_distribution()? Is this legal C syntax?


__declspec is either an extension of a particular C
implementation, or it's the name of a macro. It's not standard
C.
Why would the function body be empty?


Beats me.


(together with __declspec(naked) it makes sense if the function is
implemented in assembler. the body is needed, since the __declspec(naked)
modifyer [OT, extension] is not allowed on prototypes in VC... that is why I
was guessing at VC... directing to the MSDN)

--
John
Feb 18 '06 #4

"John Smith" <JS****@mail.net> wrote in message
news:MOKJf.39443$sa3.37126@pd7tw1no...
I ran across this code from a statistics library. The header
source code was not available.

long double __declspec(naked) poisson_distribution(int k,long
double m)
{
}
long double pdtrl(int k,long double m )
{
long double v;

if( (k < 0) || (m <= 0.0L) )
{
mtherr( "pdtrl", DOMAIN );
return( 0.0L );
}
v = k+1;
return( igamcl( v, m ) );
}

What would be the purpose of "__declspec(naked)" in the signature
of poisson_distribution()?
It removes the prologue and epilogue (i.e., stack frame), allocation of
variables, and the assembly language return statement for the procedure.
This is useful for writing interrupt service routines since you can change
the type of assembly language return, or preventing variables from being
pushed onto a stack.
Is this legal C syntax?
You'll see this with Microsoft and OpenWatcom compilers.
Why would the
function body be empty?


It should be thought of as a compiler modifier, like GCC's __attribute__(),
which is setup similar to a prototype.
Rod Pemberton

Feb 18 '06 #5

"John Smith" <JS****@mail.net> wrote in message
news:MOKJf.39443$sa3.37126@pd7tw1no...
I ran across this code from a statistics library. The header source code
was not available.

long double __declspec(naked) poisson_distribution(int k,long double m)
{
}
long double pdtrl(int k,long double m )
{
long double v;

if( (k < 0) || (m <= 0.0L) )
{
mtherr( "pdtrl", DOMAIN );
return( 0.0L );
}
v = k+1;
return( igamcl( v, m ) );
}

What would be the purpose of "__declspec(naked)" in the signature of
poisson_distribution()? Is this legal C syntax? Why would the function
body be empty?
__declspec(naked) is some sort of compiler-specific gibberish to make C
integrate with non-C code.
It is not legal, portable ANSI C, and won't compile on another compiler.
That's not the same as saying that it is bad code.

I would guess that the empty function body is a placeholder and the real
code is not written in C.

--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $6.90 paper, available www.lulu.com
Feb 19 '06 #6
On Sat, 18 Feb 2006 19:44:44 GMT, John Smith <JS****@mail.net> wrote:
I ran across this code from a statistics library. The header
source code was not available.

long double __declspec(naked) poisson_distribution(int k,long
double m)
{
}
long double pdtrl(int k,long double m )
{ <snip>
What would be the purpose of "__declspec(naked)" in the signature
of poisson_distribution()? Is this legal C syntax? Why would the
function body be empty?


As others have said, __declspec is not standard, it's an M$VC feature
perhaps adopted by some others for compatibility. In this case on that
implementation I'd bet 'naked' results in no generated code at all for
poisson_distribution just the entrypoint symbol, with the result that
calling that name actually results in calling (the body of) pdtr(),
which has the same parameters and return type and thus works --
assuming whatever igamcl() returns is in fact correct.

- David.Thompson1 at worldnet.att.net
Feb 27 '06 #7

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

Similar topics

3
by: Red | last post by:
In netscape bookmark files, there are lots of lines like this: <DT><A HREF="http://www.commondreams.org/" ADD_DATE="1091500674" LAST_CHARSET="ISO-8859-1" ID="rdf:#$uiYyb3">Common Dreams</A> I...
12
by: Raymond Hettinger | last post by:
For your amusement and edification, I'm working on a series of Python puzzles designed to highlight areas of the language known only to those who have read the docs more than once. Each of the...
8
by: Al Reynolds | last post by:
Afternoon, In an earlier thread (http://tinyurl.com/5v4aa), I described a problem I was having which was rather bizarrely solved by changing the line: "inputbox.value = numq+ag-cw-cc;" to:...
0
by: William Wisnieski | last post by:
Hello Everyone: I'm having a very strange problem occurring with my Access 2000 database. I call it the "mystery record." Here's the story: I have a query by form that returns a record set...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
1
by: David Laub | last post by:
Visual Studio .net 2003 automatically creates resx files with three entries in them. What I don't understand is: 1) sometimes additional entries are automatically placed in the resx file, and I...
14
by: jojoba | last post by:
Hi, I hope this post is ok for this group. Here's my deal: I have two computers on my LAN at home. One desktop. One laptop. Both computers are wireless enabled (and wired enabled too). I...
1
by: =?Utf-8?B?U2lzbmF6?= | last post by:
I'm having a very strange problem I can't seem to figure out and am hoping maybe somebody has seen it before. I get an exception "Cast string to date is invalid" with this chunk of code: '...
4
saputello
by: saputello | last post by:
hello, my web page looks good enough on every browser now, except that on IE a mystery "s." appears in the bottom left of the page! i can't for the life of me figure out where it's coming from....
6
by: henryrhenryr | last post by:
Hi I'm really hoping for some ideas! I have been setting up phpmailer on my server and it was working nicely on my local server so I uploaded to my live server and tested. The mystery is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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,...

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.