473,775 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function prototype declaration

Hi,

This is a simple mistake so Iam sure there is someone who can help
with it:

The the file.h:

#define IBFLEN 50000

int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;

extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,
int *IRET);

Compiling gives the following error with the function prototype:

error: parse error before numeric constant

I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an int
and not use the #define method, it might work, but I would like to
understand why this error occurs.

Thanks for your help.
/Sheldon
Feb 28 '08 #1
7 1985
Sheldon wrote:
Hi,

This is a simple mistake so Iam sure there is someone who can help
with it:

The the file.h:

#define IBFLEN 50000
This here
>
int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;

extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,
Conflicts with this. The compiler sees "..., int *50000, ..."
int *IRET);
Compiling gives the following error with the function prototype:

error: parse error before numeric constant

I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an int
and not use the #define method, it might work, but I would like to
understand why this error occurs.

Thanks for your help.
/Sheldon
Bye, Jojo
Feb 28 '08 #2
Joachim Schmitz wrote:
Sheldon wrote:
>Hi,

This is a simple mistake so Iam sure there is someone who can help
with it:

The the file.h:

#define IBFLEN 50000
This here
>>
int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
Addition: don't do this in a header file. Declare them extern here and
define them in a .c file.
Think about what otherwise happens if that header files in #include'd in
other modules of the same program
>>
extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,
Conflicts with this. The compiler sees "..., int *50000, ..."
>int *IRET);
>Compiling gives the following error with the function prototype:

error: parse error before numeric constant

I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an
int and not use the #define method, it might work, but I would like
to understand why this error occurs.

Thanks for your help.
/Sheldon
Bye, Jojo
Feb 28 '08 #3
Sheldon wrote:
Hi,

This is a simple mistake so Iam sure there is someone who can help
with it:

The the file.h:

#define IBFLEN 50000

int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;

extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,
int *IRET);

Compiling gives the following error with the function prototype:

error: parse error before numeric constant
The #define says "when you see IBFLEN, see 50000 instead". #defines
don't follow C identifier scope rules; they're just text replacement.

The pbbufr_ [try saying that three times quickly, or even slowly]
declaration becomes

extern void pbbufr_(int *IUNIT1, int *IBUFF, int *50000, int *ILEN,
int *IRET);

which is clearly wrong: argument names can't be integers.

So don't do that. An easy fix is to make your parameter names lower-case,
so they don't clash with the traditional UPPERCASEFORMAC ROS #define
name. If I were renaming them, I'd also strip of the leading `i` and
disabbreviate the name too -- but your local culture might not take
that much warping.

--
"Ashes are burning the way." - Renaissance, /Ashes Are Burning/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Feb 28 '08 #4
On 28 Feb, 10:44, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
Sheldon wrote:
Hi,
This is a simple mistake so Iam sure there is someone who can help
with it:
The the file.h:
#define IBFLEN 50000

This here
int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,

Conflicts with this. The compiler sees "..., int *50000, ..."
int *IRET);
Compiling gives the following error with the function prototype:
error: parse error before numeric constant
I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an int
and not use the #define method, it might work, but I would like to
understand why this error occurs.
Thanks for your help.
/Sheldon

Bye, Jojo
Hi Jojo,

I see but changing to ... int IBFLEN instead of int *IBFLEN results in
the same error.
Cahnging the argument to: just IBFLEN doesn't help either.
Any suggestions?
/S
Feb 28 '08 #5
Sheldon wrote:
On 28 Feb, 10:44, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
>Sheldon wrote:
>>Hi,
>>This is a simple mistake so Iam sure there is someone who can help
with it:
>>The the file.h:
>>#define IBFLEN 50000

This here
>>int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
>>extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,

Conflicts with this. The compiler sees "..., int *50000, ..."
>>int *IRET);
Compiling gives the following error with the function prototype:
>>error: parse error before numeric constant
>>I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an
int and not use the #define method, it might work, but I would like
to understand why this error occurs.
>>Thanks for your help.
/Sheldon

Bye, Jojo

Hi Jojo,

I see but changing to ... int IBFLEN instead of int *IBFLEN results in
the same error.
Indeed, as 'int 50000' is as illegal as 'int *50000'
Cahnging the argument to: just IBFLEN doesn't help either.
Any suggestions?
Drop the variable names, in prototyps the ain't needed. Or make them
lowercase, as Chris Dollin suggested, this would be needed in the function
definition anyway.

Bye, Jojo
Feb 28 '08 #6
On 28 Feb, 11:08, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
Sheldon wrote:
On 28 Feb, 10:44, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
Sheldon wrote:
Hi,
>This is a simple mistake so Iam sure there is someone who can help
with it:
>The the file.h:
>#define IBFLEN 50000
This here
>int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
>extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,
Conflicts with this. The compiler sees "..., int *50000, ..."
>int *IRET);
Compiling gives the following error with the function prototype:
>error: parse error before numeric constant
>I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an
int and not use the #define method, it might work, but I would like
to understand why this error occurs.
>Thanks for your help.
/Sheldon
Bye, Jojo
Hi Jojo,
I see but changing to ... int IBFLEN instead of int *IBFLEN results in
the same error.

Indeed, as 'int 50000' is as illegal as 'int *50000'
Cahnging the argument to: just IBFLEN doesn't help either.
Any suggestions?

Drop the variable names, in prototyps the ain't needed. Or make them
lowercase, as Chris Dollin suggested, this would be needed in the function
definition anyway.

Bye, Jojo- Dölj citerad text -

- Visa citerad text -
I see. I understand. Made them lower case now and will remove the
names.

Thanks!

/S
Feb 28 '08 #7
Sheldon <sh******@gmail .comwrites:
On 28 Feb, 10:44, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
wrote:
>Sheldon wrote:
This is a simple mistake so Iam sure there is someone who can help
with it:
The the file.h:
#define IBFLEN 50000

This here
int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
extern void pbbufr_(int *IUNIT1, int *IBUFF, int *IBFLEN, int *ILEN,

Conflicts with this. The compiler sees "..., int *50000, ..."
int *IRET);
Compiling gives the following error with the function prototype:
error: parse error before numeric constant
I have tried several variations but I am at a lost as the to true
cause. The function is from a FORTRAN library and as such the
arguments must be addresses and not copy. If I change IBFLEN to an int
and not use the #define method, it might work, but I would like to
understand why this error occurs.
[...]
>
I see but changing to ... int IBFLEN instead of int *IBFLEN results in
the same error.
Cahnging the argument to: just IBFLEN doesn't help either.
Any suggestions?
You're using the same name, IBFLEN, for a macro and for a function
parameter.

You're also using the same names for several int objects and for
several other parameters: IRET, ILEN, IUNIT1. But several of the
parameters aren't also declared as variables, and vice versa.

It looks like you're trying to write Fortran in C, though I don't know
Fortran well enough to understand the details. In C, function
parameters only need to be declared in the prototype; you don't need
to declare them separately.

Furthermore, variables can be *declared* in headers, but they
shouldn't be *defined* in headers, as you've done here. And if the C
code that uses the header doesn't need to refer to the variables, you
don't need to declare them in the header at all.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 28 '08 #8

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

Similar topics

1
4949
by: Dave Theese | last post by:
Consider the following declaration *inside of a function*: int j(int); My compiler (VC++ 7.1) accepts this. typeid returns a type of int __cdecl(int). Local functions are not legal in C++. Is this an error or... Is there some reason it would be legal to declare (but not define) a
21
3857
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one would only really need to use a function
28
15391
by: Michael B. | last post by:
I tend to use rather descriptive names for parameters, so the old style of declaration appeals to me, as I can keep a declaration within 80 chars: void * newKlElem (frame_size,num_blocks,num_frames,frame_locator) size_t frame_size; unsigned short num_blocks; unsigned short num_frames; Kl_frame_locator *locator; { /* code goes here */
6
7995
by: Daniel Nichols | last post by:
I've noticed that in a C module (.c, .h file combination) that if you create a function's definition before it is used in other functions than a declaration is not necessary. I believe if the compiler can find the definition of the function prior to encountering the use of the function it will generate the prototype itself. I don't currently use this feature, I explicitly create declarations for all functions in a header file. However, I...
11
1932
by: Neo | last post by:
Why the following code is compilable? The function abc() doesn't take any arguments, still i can call the function with arbitraty number of arguments. Even compiler doesn't show any warning. What the standard says? ----- file1.c ------ extern unsigned abc(); int main() { unsigned *chip_offset; abc(&chip_offset, 10);
6
2098
by: dndfan | last post by:
Hello, In the short time I have spent reading this newsgroup, I have seen this sort of declaration a few times: > int > func (string, number, structure) > char* string > int number > struct some_struct structure
20
2376
by: Christian Christmann | last post by:
Hi, in a benchmark I've found an uncommon use of a function. This is the simplified form: 1 int foo( int f ) 2 { 3 return f; 4 } 5
29
8088
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the difference between a function prototype and a function declaration? If you get this right, you must have done fair amount of research on C
20
2244
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to think my way through what I want to do now. I don't know why - I'm fine with most other aspects of the language, but my brain goes numb when I'm reading about function pointers! I would like to have an array of structures, something like
8
2390
by: vaib | last post by:
hi all , It really seems that C never ceases to amaze . All this time i've been doing C and i thought i was quite adept at it but i was wrong . So without wasting any more time , here's the confusion . I read in K&R that ANSI introduced the concept of function prototyping in C and it was missing there initially ( it borrowed the concept from C++ ) _but_ it did it make it compulsory to actually include the function declaration in the...
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
10268
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10107
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
10048
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,...
0
8939
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
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
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
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
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.