473,772 Members | 3,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird (?) explicit declaration of functions

Hello

I have read about a C shared library which I want to use in my C
program. (It's a library to encode/decode packets from/to a serial bus
running with the SNAP-protocol).

Unfortunatly there is no source code available, just a C file with
function declarations like:

long SendData(TXData )Type_TXData *TXData;
Void GetStatistics(S tat)Type_Statis tics *Stat;

My problem is, I don't understand what it means. Is it equivalent to
long SendData(Type_T XData *TXData);
- which makes a lot more sense to me?

Is there a good reason to use this strange syntax?

Nils Emil
--
My reply-address is valid. www.bios-flash.dk
Min svar-adresse er gyldig. Redning af døde BIOS'er
Nov 14 '05 #1
2 2321
Nils Emil P. Larsen <ne********@pos t.cybercity.dk> scribbled the following:
Hello I have read about a C shared library which I want to use in my C
program. (It's a library to encode/decode packets from/to a serial bus
running with the SNAP-protocol). Unfortunatly there is no source code available, just a C file with
function declarations like: long SendData(TXData )Type_TXData *TXData;
Void GetStatistics(S tat)Type_Statis tics *Stat; My problem is, I don't understand what it means. Is it equivalent to
long SendData(Type_T XData *TXData);
- which makes a lot more sense to me?
It appears to be a K&R1-style declaration, which predates ISO C, and is
now considered obsolete.
Is there a good reason to use this strange syntax?


No, if not for legacy compability.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Life without ostriches is like coffee with milk."
- Mika P. Nieminen
Nov 14 '05 #2
>Nils Emil P. Larsen <ne********@pos t.cybercity.dk> scribbled the following:
... Unfortunatly there is no source code available, just a C file with
function declarations like:
long SendData(TXData )Type_TXData *TXData;
Void GetStatistics(S tat)Type_Statis tics *Stat;
In article <cb**********@o ravannahka.hels inki.fi>
Joona I Palaste <pa*****@cc.hel sinki.fi> writes:
It appears to be a K&R1-style declaration, which predates ISO C, and is
now considered obsolete.
While:

Tfunc funcname(arg1, arg2)
Targ1 arg1;
Targ2 arg2;

is indeed K&R-1 ("pre-ANSI" or "Classic C") syntax, it is not valid
as a *declaration*, only as a *definition*, and it must be followed
by the open brace of the function, e.g.:

int main(argc, argv)
int argc;
char **argv;
{
/* local variables here */
...
return 0;
}

The parameters "argc" and "argv" become local (block-scope) variables
inside the function in the usual way, just as with prototype-syntax
parameters. (The fact that the scope of argc and argv is the same as
that of any block-scope variable declared right after the "{" is the
reason I eventualy adopted the indentation shown above, for K&R-1 C.)

At least one K&R-style compiler would, if given something like the
above as a declaration, do something very bad:

void f1(arg) int arg; /* ERROR -- no function body */
char *f2(arg) char *arg; /* ERROR -- no function body */
int main(argc, argv) int argc; char **argv; { ... }

Here the variables "argc" and "argv" would exist as one expected,
but have the wrong internal addresses, and the stack would get
wrecked.
Is there a good reason to use this strange syntax?

No, if not for legacy compability.


Indeed.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #3

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

Similar topics

11
1598
by: Anon Email | last post by:
Hey people, This looks really weird. I can't make sense of it. Is this a mistake? Can anyone help? IStack const & GetStack () const; Cheers,
2
6774
by: alice | last post by:
Hi, When I compiles the following program with g++, it gives the following output: # g++ -o list list.C list.C: In function `int main()': list.C:116: jump to case label list.C:110: crosses initialization of `std::string data' list.C:120: jump to case label list.C:110: crosses initialization of `std::string data'
3
5823
by: Holger (David) Wagner | last post by:
Hi all, we're currently developing an application in the .NET environment that needs to access a DLL implemented in Fortran. There is one procedure with about 17 parameters, most of them arrays. After some trial and error experiments, we've found out that a) the parameters must be ordered by type, i.e. we cannot mix double, integers and Strings (char-Arrays) - instead, we first need to put all the float-Arrays and Int32-Arrays, and...
1
1992
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following: ****************************************************************** template<typename T> void from_string(const char Str, T &Obj); template<> void from_string(const char Str, long &); // template<> void from_string(const char Str, unsigned lon &); //
4
1327
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to create. -Thank you very much for leading me on to Classes. Ok here is my code. ( see below )
2
2355
by: vlsidesign | last post by:
Here is my a portion of my program: #include <stdio.h> main() { int fahr, celsius; int lower, upper, step; int fc_conv(int fahr); ... snip ... }
2
3074
by: greg | last post by:
In my quest to eliminate C compiler warnings from Pyrex output, I've discovered some utterly bizarre behaviour from gcc 3.3. The following code: void g(struct foo *x) { } void f(void) {
2
7699
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
3
1345
by: Jja | last post by:
Hello, I am very new to this site. before i start may i first introduce myself i am 'Jhalil, a beginner Vb6 programmer. i stumbled on this site on my quest for a code in vb that can connect me to either Microsoft sql or Mysql server. Infact i was suprised to see people with different programming problems. That is how i became a member of this good family. Now can anybody help? i am a beginner in VB 6, i enjoy writing codes but i do...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10104
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7460
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.