When to define functions in C?


 
Thread Tools Search this Thread
Top Forums Programming When to define functions in C?
# 8  
Old 03-31-2014
If you had to compile all of stdio whenever you did #include <stdio.h>, for example, that would be a real pain. But instead, it can just include a lot of definition-less declarations, and let you find the functions inside a library file when it gets linked.

It also lets someone give you a library file without necessarily giving you the code that made it(though inevitably system-specific).
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Define Variables

Hi, I just define the variable in script and use those script in another script but the variable not recognize. test1.sh #!/bin/bash DB="test_db" USR="test_user" PWD="test_pwd" HST="24.254.87.12" test2.sh #!/bin/bash ./test1.sh mysql -u $USR -p $PWD -h $HST... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Define variable from file.

HI I have file A.txt _1A _2A _3A _4A I want define all as different variable. $1A=_1A $2B=_2A $3C=_3A $4D=_4A Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

4. Programming

#define in c

Hi, I had a head file, looks like #define MIN_NUM 10 #define MAX_NUM 10 is there any way to get "MAX_NUM" from 10? thanks. peter (9 Replies)
Discussion started by: laopi
9 Replies

5. Programming

help with #define in C

if i do this in C #define NUM 1234512345 then how come i cant print it out using int main(int argc, char **argv) { printf("%d\n", NUM); return 0; } well the result is -1219236538, why isnt it 1234512345 ? (7 Replies)
Discussion started by: omega666
7 Replies

6. Programming

#define

Hello, I would like to conditionaly comment in my code source some fields from arrays. So I use the property ## from the #define definition. my code: ... #define slet /##* #define etsl *##/ ... const T_SVT_ADLL_A653_DESC A_DESC = { { slet qwerty etsl SLICING,... (3 Replies)
Discussion started by: cypleen
3 Replies

7. UNIX for Dummies Questions & Answers

#define in perl

Hi friends, I am not sure if perl questions can be raised here. :rolleyes: But I have a doubt if there is a way to do "#define" in perl, like in C. Does anyone know if it is feasible (without CPAN modules)? Thanks, Srini (7 Replies)
Discussion started by: srinivasan_85
7 Replies

8. Programming

mysterious #define

in the header file orville.h, outside of the #ifdef #endif , there is the following #define JOB_CONTROL /* support job-control */ As you can see, the JOB_CONTROL macro has no value associated with it. Here is what I go when I ran grep on the entire source code. $ grep -iR... (6 Replies)
Discussion started by: frequency8
6 Replies
Login or Register to Ask a Question
DNET_DAEMON(3)						     Library Functions Manual						    DNET_DAEMON(3)

NAME
dnet_daemon, dnet_accept, dnet_reject - DECnet daemon functions SYNOPSIS
#include <netdnet/dn.h> #include <netdnet/dnetdb.h> -ldnet -ldnet_daemon -lcrypt int dnet_daemon (int object, char *named_object, int verbosity, int do_fork) void dnet_accept (int sockfd, short status, char *data, int len) void dnet_reject (int sockfd, short status, char *data, int len) DESCRIPTION
These functions are the core of writing a DECnet daemon under Linux. They provide all the functionality necessary to have a daemon that will run standalone or be forked from the dnetd(8) DECnet super-server. (see dnetd.conf(3) for information on configuring dnetd. dnet_daemon() returns a connected file descriptor which your daemon program uses to talk to the remote client. If your daemon is run from dnetd then this will be it's standard input. object is the numbered object which your daemon binds to. Alternatively you can bind to a named_object in which case the object number should be zero. verbosity determines how much logging the daemon functions will do. 0 means no logging, 1 is fairly verbose logging. Anything higher is useful only for debugging. do_fork If this is set then, when running standalone, the daemon will fork and detach itself from the parent process. dnet_accept() You MUST call this or dnetd_reject() after receiving a valid file descriptor from dnet_daemon. The optional data and status parameters provide extra information to the connecting host. See below for status values. dnet_reject() If you wish to reject the connection for any reason the call this function instead of dnet_accept() with the status set to the reason (see below) you are rejecting the connection. If your daemon is authenticated by dnetd then connections will already be rejected if they are not correctly authorized by either a valid username/password or the proxy database (see decnet.proxy(3) ) Here is a list of status codes available in dnetd.conf: #define DNSTAT_REJECTED 0 /* Rejected by object */ #define DNSTAT_RESOURCES 1 /* No resources available */ #define DNSTAT_NODENAME 2 /* Unrecognised node name */ #define DNSTAT_LOCNODESHUT 3 /* Local Node is shut down */ #define DNSTAT_OBJECT 4 /* Unrecognised object */ #define DNSTAT_OBJNAMEFORMAT 5 /* Invalid object name format */ #define DNSTAT_TOOBUSY 6 /* Object too busy */ #define DNSTAT_NODENAMEFORMAT 10 /* Invalid node name format */ #define DNSTAT_REMNODESHUT 11 /* Remote Node is shut down */ #define DNSTAT_ACCCONTROL 34 /* Access control rejection */ #define DNSTAT_NORESPONSE 38 /* No response from object */ #define DNSTAT_NODEUNREACH 39 /* Node Unreachable */ /* Disconnect notification errors */ #define DNSTAT_MANAGEMENT 8 /* Abort by management/third party */ #define DNSTAT_ABORTOBJECT 9 /* Remote object aborted the link */ #define DNSTAT_FAILED 38 /* Node or object failed */ #define DNSTAT_NODERESOURCES 32 /* Node does not have sufficient resources for a new link */ #define DNSTAT_OBJRESOURCES 33 /* Object does not have sufficient resources for a new link */ #define DNSTAT_BADACCOUNT 36 /* The Account field in unacceptable */ #define DNSTAT_TOOLONG 43 /* A field in the access control message was too long */ EXAMPLE
Here is an example MIRROR server. The real mirror server is built into dnetd. This also illustrates the logging functions in libdnetd_dae- mon. #include <sys/types.h> #include <sys/socket.h> #include <stdarg.h> #include <syslog.h> #include <netdnet/dnetdb.h> #include <netdnet/dn.h> int main(int argc, char *argv[]) { int insock; /* Set up logging. The parameters are: * daemon name to use * 's' means log to syslog */ init_daemon_logging("mirror", 's'); // Wait for something to happen (or check to see if it already has) insock = dnet_daemon(DNOBJECT_MIRROR, NULL, 0, 1); // Make sure we got a valid socket if (insock > -1) { int readnum; char condata[] = {0x00, 0x20}; // Actually 4096 as a LE word char ibuf[4096]; /* We must accept the connection */ dnet_accept(insock, 0, condata, 2); while ( (readnum=read(insock,ibuf,sizeof(ibuf))) > 0) { ibuf[0]=0x01; if (write(insock,ibuf,readnum) < 0) { DNETLOG((LOG_WARNING, "mirror, write failed: %m ")); close(insock); break; } } close(insock); } return 0; } To compile: gcc mirror.c -omirror -ldnet -ldnet_daemon -lcrypt SEE ALSO
dnetd(8), dnet_addr(3), dnet_ntoa(3), dnet_conn(3), getnodeadd(3), getnodebyname(3), getnodebyaddr(3), setnodeent(3), decnet.proxy(5) DECnet daemon functions May 3, 1999 DNET_DAEMON(3)