LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-26-2012, 09:14 PM   #1
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Rep: Reputation: 4
usage of _PROTOTYPE ?


part of codes
....
<code>

#if 0
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(void count, (FILE *f));
_PROTOTYPE(void usage, (void));
#endif

int main (int argc, char **argv);
void count (FILE *f);
void usage (void);

int main(argc, argv)
int argc;
char *argv[];
{
int k;
char *cp;
int tflag, files;

</code>
....
more codes

and this compiled OK

I have two questions. the function prototype is ansi style and function definition is K&R style how does compiler compiles this codes OK if they do not match in style?

and How do you use _PROTOTYPE macro

Thank you for reading my post.
 
Old 09-26-2012, 10:33 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Don't use this _PROTOTYPE macro. Actually, you can safely delete everything between #if 0 and #endif.
Don't use non-ANSI compilers either -- it's 2012 now, not 1982.
Do use [code] and [/code] tags.

PS: the old-style function-parameter-definition is still usable, but obsolete.

Last edited by NevemTeve; 09-26-2012 at 10:36 PM.
 
Old 09-26-2012, 11:25 PM   #3
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
The code is from i think around 1985. since I'm re-writing the old code, I'm not gonna use the _PROTOTYPE macro but I still do need to understand how things work.

I'll appreciate if someone takes a time and explains this.
 
Old 09-27-2012, 02:20 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Do you have any questions I haven't answered yet?

> I have two questions.
> The function prototype is ansi style and function definition is K&R style how does compiler compiles this codes OK if they do not match in style?

There is nothing preventing using both styles, but in new programs you shouldn't use old style.

> How do you use _PROTOTYPE macro?

You don't. You see it is between #if 0 and #endif, meaning: 'dear compiler, ignore this part'

Last edited by NevemTeve; 09-27-2012 at 02:24 AM.
 
Old 09-27-2012, 03:27 PM   #5
babbab
Member
 
Registered: Mar 2010
Distribution: slackware64 current
Posts: 104

Original Poster
Rep: Reputation: 4
> Do you have any questions I haven't answered yet?

No.. I thank you for answering it, appreciate it

>> How do you use _PROTOTYPE macro?

> You don't. You see it is between #if 0 and #endif, meaning: 'dear compiler, ignore this part'

.. I quoted with #if 0, #endif to see the effect. and put ansi style prototype. I was surprised to see the source was compiled without any errors.

I guess what I was expecting was more like there is this kind of macro code somewhere else then that expands above code and it has effect of resulting such such... then it compiles the above code without any errors
 
Old 09-28-2012, 02:57 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Note: I guess this _PROTOTYPE macro might be sg like this:

Code:
#ifdef __STDC__
    #define _PROTOTYPE(begin, end) begin end
#else
    #define _PROTOTYPE(begin, end) begin ()
#endif
So it doesn't do anything non-trivial:

Code:
input:  _PROTOTYPE(void count, (FILE *f));
output: void count (FILE *f);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
processes/CPU Usage/Mem Usage desktop wallpaper ceantuco Linux - Newbie 2 04-13-2009 01:14 PM
X hangs after prolonged usage ... memory usage goes upto 195MB duryodhan Slackware 18 05-10-2007 06:16 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration