Basic signal and alarm usage


 
Thread Tools Search this Thread
Top Forums Programming Basic signal and alarm usage
# 15  
Old 05-29-2007
Quote:
Not true, they *are* required if the function has not already been seen and returns anything other than an int. This is true even in K&R C.
Yes.
Code:
#include <stdio.h>

//char* fun(int);

int main()
{
  fun(10);
  return 0;
}

char* fun(int a) {
  return "";
}

Upon compilation,
implicit declaration of ' int ' would be considered for the function fun ' fun ' while the definition is returning ' char* '

IMHO, signatures are a must.
# 16  
Old 05-29-2007
Quote:
Originally Posted by porter
Not true, they [function prototypes] *are* required if the function has not already been seen and returns anything other than an int. This is true even in K&R C.
No, that is not true. Function definitions are what would be required in the cases you cite. Function prototypes did not arrive until Ansi C. You have the two mixed up.

function definition: int handler();
function prototype: int handler(int);

The original C language did not support prototypes and, while they are a good idea, they are not required now.
# 17  
Old 05-29-2007
Quote:
Originally Posted by Perderabo
The original C language did not support prototypes and, while they are a good idea, they are not required now.
so what will the following do?

Code:
main()
{
long l=get_number();

      printf("%ld\n",l);

      return 0;
}

double get_number()
{
     return 3.141592654;
}

# 18  
Old 05-29-2007
Quote:
Originally Posted by porter
so what will the following do?
I guess it demonstrates that you are able to generate an incorrect program that doesn't use function prototypes. This suggests that you think this is proof that function prototypes are required and possibly even that the original K&R C supported or required function prototypes. It must at least be true that you think the addition of a function prototype is the only way to fix the program. (I remain convinced that a function definition would fix it as well.) Oh well, at least you finally contributed some code to this thread.

A quote for anyone who is interested...

Quote:
A note of history: The biggest change between ANSI C and earlier versions is how functions are declared and defined.
...
The new syntax of function prototypes makes it much easier for a compiler to detect errors in the number of arguments or their types. The old style of declaration and definition still works in ANSI C, at least for a transition period, but we strongly recommend that you use the new form when you have a compiler that supports it.
From The C Programming Language Second Edition by Brian Kernighan and Dennis Ritchie

porter, you and I will simply have to agree to disagree on whether or not function prototypes are currently required as well as whether or not function prototypes were supported (or required) by the original K&R C. I am closing this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic sed usage in shell script

Hi, A basic sed question. I have a set of files. In each file there is a number that I want replaced. For example, if I run sed I should get the following: % cat test2.txt #goofy//171.00 goofy 171.00 % sed -i 's/171/xxx/g' test2.txt % cat test2.txt #goofy//xxx.00 goofy xxx.00 ... (2 Replies)
Discussion started by: pc2001
2 Replies

2. Shell Programming and Scripting

basic computer usage report

Our small company, about 5 users, need a basic script that scans mapped network drives (example: drive b,c,d, e, and f) for hard drive usage. This needs to send a report to myself in any type of basic notepad format (easy to read and decipher) for drives that have reached 80% usage... any ideas? ... (1 Reply)
Discussion started by: jessessays
1 Replies

3. Programming

alarm signal processing

I'm writing a function right now, and I want to set an alarm to avoid a timeout, here's the general idea of my code: int amt = -2; alarm(10); amt = read(fd, &t->buf, TASKBUFSIZ - tailpos); //do a read when the alarm goes off, i want to check the value of "amt" ... (1 Reply)
Discussion started by: liaobert
1 Replies

4. Solaris

False Memory usage alarm!!

Hi Experts, I am using Solaris-10, Sun-Fire-V445. i got often the below message- "Memory Usage – Critical, Memory usage (RAM) exceeding 90% The memory utilization is exceeding 90%" in a application running on solaris. I checked with Vmstat. Everything seems to be fine. Where i should... (5 Replies)
Discussion started by: thepurple
5 Replies

5. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

6. Programming

Usage of exit() inside a signal handler

Is it ok to use exit() inside a signal handler? I catch SIGUSR1 in a signal handler and I try to close a file and then exit. The result is inconsistent. Sometimes the process exit and sometimes it returns to the original state before the signal handler was invoked. Perhaps exit is not legal in... (8 Replies)
Discussion started by: Tuvia
8 Replies

7. Shell Programming and Scripting

Basic bash 'for loop' usage

Hi! I have a simple question about using a for loop. I'm trying to open up all the zip files in the currect directory with ark, but I am getting the error "bash: syntax error near unexpected token `for $i ; do ark $i ; done ; I looked in the info pages for bash, but I can't seem to figure... (2 Replies)
Discussion started by: Orange Stripes
2 Replies

8. AIX

basic question about disk usage

how to i find out the disk usage on a server. say in windows examples its like C:/ D:/ and checking out the disk space. how can i find in Unix. can i just use df -k (3 Replies)
Discussion started by: karthikosu
3 Replies

9. Shell Programming and Scripting

Perl alarm signal

I am trying to write a signal to exit when a process times out. What I have come up with from poking around the web is this. #!/usr/bin/perl eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX... (2 Replies)
Discussion started by: reggiej
2 Replies

10. UNIX for Dummies Questions & Answers

Alarm signal

Hi, when I execute a script on unix AIX, I've got an error message: "Execution: 85328 Signal d'alarme". If I edit this file with "vi", I ve got the same error after a while (about 1 minute). If I try with another user I still have the problem. But if I rename this file, no problem. My... (5 Replies)
Discussion started by: cgsteph
5 Replies
Login or Register to Ask a Question