473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Function & header files

how to convert a program to a function/macro and put it in a header
file? is there any shortcut method for this?
thanks.

Jun 12 '07 #1
34 1917
Umesh said:
how to convert a program to a function/macro and put it in a header
file?
Don't even try. Instead, find out how to use libraries.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 12 '07 #2
On 12 Jun, 14:05, Richard Heathfield <r...@see.sig.invalidwrote:
Umesh said:
how to convert a program to a function/macro and put it in a header
file?

Don't even try. Instead, find out how to use libraries.
Now you've done it. If he picks up on this (he may not, as he
generally wants to be spoonfed a direct answer to his question), he'll
now ask "how to use libraries?" and we'll have a heap of "off-topic"
responses...

Jun 12 '07 #3
How can I convert a function to a macro in general? e.g.

void factorial(int n)
{
long int x=1;
for (int i=1;i<=n;i++)
x*=i;
printf("Factorial of %d = %ld\n",n,x);
}

Jun 12 '07 #4
Umesh wrote:

| How can I convert a function to a macro in general? e.g.
|
| void factorial(int n)
| {
| long int x=1;
| for (int i=1;i<=n;i++)
| x*=i;
| printf("Factorial of %d = %ld\n",n,x);
| }

Sorry - there is no "general solution". Please re-read Richard's
article.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
Jun 12 '07 #5
Umesh said:
How can I convert a function to a macro in general? e.g.

void factorial(int n)
{
long int x=1;
for (int i=1;i<=n;i++)
x*=i;
printf("Factorial of %d = %ld\n",n,x);
}
You'd be better off asking "how can I avoid risking the generation of
incorrect results?"

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 12 '07 #6
Richard Heathfield <rj*@see.sig.invalidwrites:
Umesh said:
>How can I convert a function to a macro in general? e.g.

void factorial(int n)
{
long int x=1;
for (int i=1;i<=n;i++)
x*=i;
printf("Factorial of %d = %ld\n",n,x);
}

You'd be better off asking "how can I avoid risking the generation of
incorrect results?"
He'd be *far* better off asking "How do I use this Usenet thing
without looking like a parasite?".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 12 '07 #7
Umesh wrote:
>
How can I convert a function to a macro in general? e.g.

void factorial(int n)
{
long int x=1;
for (int i=1;i<=n;i++)
x*=i;
printf("Factorial of %d = %ld\n",n,x);
}
A function that declares local variables,
is a poor candidate for conversion to a macro.

/* BEGIN new.c */

#include <stdio.h>

#define factorial(N) \
do { \
n = N; \
x = i = 1; \
while (n >= i) { \
x *= i++; \
} \
printf("Factorial of %d = %ld\n", n, x); \
} while (0)

void (factorial)(int n);

int main(void)
{
long int x = 1, i = 1, n;

factorial(5);
(*factorial)(5);
return 0;
}

void (factorial)(int n)
{
long int x = 1, i = 1;

factorial(n);
}

/* END new.c */
--
pete
Jun 12 '07 #8
// factorial by macro

#include<stdio.h>
#define factorial(n) \
long int x=1; \
for(int i=1;i<=n;i++) \
x*=i; \
printf("Factorial of %d = %ld\n",n,x);\

main()
{
int n;
printf("Enter No.- ");
scanf("%d",&n);
factorial(n);
return 0;
}

Jun 13 '07 #9
Umesh said:
// factorial by macro

#include<stdio.h>
#define factorial(n) \
long int x=1; \
for(int i=1;i<=n;i++) \
x*=i; \
printf("Factorial of %d = %ld\n",n,x);\

main()
{
int n;
printf("Enter No.- ");
scanf("%d",&n);
factorial(n);
return 0;
}
foo.c:9: warning: return-type defaults to `int'
foo.c:9: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:13: parse error before `long'
foo.c:13: parse error before `int'
foo.c:13: `i' undeclared (first use in this function)
foo.c:13: (Each undeclared identifier is reported only once
foo.c:13: for each function it appears in.)
foo.c:13: warning: statement with no effect
foo.c:13: parse error before `)'
foo.c:13: `x' undeclared (first use in this function)
make: *** [foo.o] Error 1

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 13 '07 #10
Richard Heathfield <rj*@see.sig.invalidwrites:
Umesh said:
>// factorial by macro

#include<stdio.h>
#define factorial(n) \
long int x=1; \
for(int i=1;i<=n;i++) \
x*=i; \
printf("Factorial of %d = %ld\n",n,x);\

main()
{
int n;
printf("Enter No.- ");
scanf("%d",&n);
factorial(n);
return 0;
}

foo.c:9: warning: return-type defaults to `int'
foo.c:9: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:13: parse error before `long'
foo.c:13: parse error before `int'
[snip]

Umesh is obviously using a compiler that implements some C99 features.
Using such features isn't wrong, merely non-portable. When I compile
with "gcc -std=c99 -pedantic -Wall -W -O3", the only diagnostic I get
is "warning: return type defaults to `int'".

Of course, the program is horribly bad for other reasons. The use of
a macro is entirely gratuitous, and the macro unaccountably prints the
result rather than yielding it as a result.

Here's another program that uses a macro to compute factorials:

#include <stdio.h>

static unsigned long factorial_func(unsigned n)
{
unsigned long f = 1;
unsigned i;
for (i = 2; i <= n; i ++) {
f *= i;
}
return f;
}

#define factorial(n) factorial_func(n)

int main(void)
{
unsigned n;
printf("Enter number: ");
scanf("%u", &n);
printf("factorial(%u) = %lu\n", n, factorial(n));
return 0;
}

The use of a macro is equally gratuitous, but at least this one
operates more usefully. On a system with 32-bit longs, either program
works only for arguments up to 12; using unsigned long rather than
long didn't add enough range to change that. With 64-bit longs, it
works for arguments up to 20. Neither version checks for overflow
(which would be fairly difficult to do), but my version uses unsigned
arithmetic and therefore avoids undefined behavior. The use of scanf
for input is dangerous, as I've discussed here before, but I was too
lazy to correct it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 13 '07 #11
Which compiler do you use?
It's working fine in TC++ 3/4.5 & VC++ 6

Jun 14 '07 #12
Umesh said:
Which compiler do you use?
When writing C programs, I am perfectly content to use *any* compiler
that supports either ISO/IEC 9899:1990 when invoked in conforming mode
or ISO/IEC 9899:1999 when invoked in conforming mode.
It's working fine in TC++ 3/4.5 & VC++ 6
Neither of those compilers claims to conform to ISO/IEC 9899:1999. They
do, however, claim to conform to ISO/IEC 9899:1990, so that's the
standard by which programs written for them should be judged. By that
standard, your program is invalid for the reasons stated.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 14 '07 #13
WHICH COMPILER(S) DO YOU USE?

GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.

GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly

Richard Heathfield wrote:
Umesh said:
Which compiler do you use?

When writing C programs, I am perfectly content to use *any* compiler
that supports either ISO/IEC 9899:1990 when invoked in conforming mode
or ISO/IEC 9899:1999 when invoked in conforming mode.
It's working fine in TC++ 3/4.5 & VC++ 6

Neither of those compilers claims to conform to ISO/IEC 9899:1999. They
do, however, claim to conform to ISO/IEC 9899:1990, so that's the
standard by which programs written for them should be judged. By that
standard, your program is invalid for the reasons stated.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 15 '07 #14

"Umesh" <fr****************@gmail.comha scritto nel messaggio
news:11*********************@z28g2000prd.googlegro ups.com...
WHICH COMPILER(S) DO YOU USE?

GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.

GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly
Well, I see that at least you know how to copy and paste.
>
Richard Heathfield wrote:
>Umesh said:
Which compiler do you use?

When writing C programs, I am perfectly content to use *any* compiler
that supports either ISO/IEC 9899:1990 when invoked in conforming mode
or ISO/IEC 9899:1999 when invoked in conforming mode.
It's working fine in TC++ 3/4.5 & VC++ 6

Neither of those compilers claims to conform to ISO/IEC 9899:1999. They
do, however, claim to conform to ISO/IEC 9899:1990, so that's the
standard by which programs written for them should be judged. By that
standard, your program is invalid for the reasons stated.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

Jun 15 '07 #15

"Keith Thompson" <ks***@mib.orgha scritto nel messaggio
news:ln************@nuthaus.mib.org...
Richard Heathfield <rj*@see.sig.invalidwrites:
>Umesh said:
>>// factorial by macro

#include<stdio.h>
#define factorial(n) \
long int x=1; \
for(int i=1;i<=n;i++) \
x*=i; \
printf("Factorial of %d = %ld\n",n,x);\

main()
{
int n;
printf("Enter No.- ");
scanf("%d",&n);
factorial(n);
return 0;
}

foo.c:9: warning: return-type defaults to `int'
foo.c:9: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:13: parse error before `long'
foo.c:13: parse error before `int'
[snip]

Umesh is obviously using a compiler that implements some C99 features.
Using such features isn't wrong, merely non-portable. When I compile
with "gcc -std=c99 -pedantic -Wall -W -O3", the only diagnostic I get
is "warning: return type defaults to `int'".

Of course, the program is horribly bad for other reasons. The use of
a macro is entirely gratuitous, and the macro unaccountably prints the
result rather than yielding it as a result.

Here's another program that uses a macro to compute factorials:

#include <stdio.h>

static unsigned long factorial_func(unsigned n)
{
unsigned long f = 1;
unsigned i;
for (i = 2; i <= n; i ++) {
f *= i;
}
return f;
}

#define factorial(n) factorial_func(n)

int main(void)
{
unsigned n;
printf("Enter number: ");
scanf("%u", &n);
printf("factorial(%u) = %lu\n", n, factorial(n));
return 0;
}

The use of a macro is equally gratuitous, but at least this one
operates more usefully. On a system with 32-bit longs, either program
works only for arguments up to 12; using unsigned long rather than
long didn't add enough range to change that. With 64-bit longs, it
works for arguments up to 20. Neither version checks for overflow
(which would be fairly difficult to do)
#include <limits.h>
#include <errno.h>
long factorial(int n)
{
long f = 1;
int i;
if (n < 0) {
errno = EDOM;
return n % 2 ? LONG_MIN : LONG_MAX;
}
for (i = 1; i <= n; i++) {
if (f LONG_MAX / i) {
errno = ERANGE;
return LONG_MAX
} else
f *= i;
}
errno = 0;
return f;
}
Fairly difficult?

Jun 15 '07 #16
On Fri, 15 Jun 2007 17:33:40 +0200, in comp.lang.c , "Army1987"
<pl********@for.itwrote:
>
"Keith Thompson" <ks***@mib.orgha scritto nel messaggio
news:ln************@nuthaus.mib.org...
>>
The use of a macro is equally gratuitous, but at least this one
operates more usefully.
....
>>Neither version checks for overflow
(which would be fairly difficult to do)
(snip code)
>Fairly difficult?
Remember, you're callling this via a macro.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 15 '07 #17
Keith Thompson <ks***@mib.orgwrites:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Umesh said:
>>// factorial by macro
<code and compiler diagnostics snipped>
Of course, the program is horribly bad for other reasons. The use of
a macro is entirely gratuitous, and the macro unaccountably prints the
result rather than yielding it as a result.

Here's another program that uses a macro to compute factorials:

#include <stdio.h>

static unsigned long factorial_func(unsigned n)
{
unsigned long f = 1;
unsigned i;
for (i = 2; i <= n; i ++) {
f *= i;
}
return f;
}

#define factorial(n) factorial_func(n)

int main(void)
{
unsigned n;
printf("Enter number: ");
scanf("%u", &n);
printf("factorial(%u) = %lu\n", n, factorial(n));
return 0;
}

The use of a macro is equally gratuitous, but at least this one
operates more usefully. On a system with 32-bit longs, either program
works only for arguments up to 12; using unsigned long rather than
long didn't add enough range to change that. With 64-bit longs, it
works for arguments up to 20. Neither version checks for overflow
(which would be fairly difficult to do),
It has just struck me that these two statements are at odds. If one
really needed an absolutely cast-iron, overflow-safe factorial
function, one would just use a look up table. Even in a future C with
256 bit integers, you'd only need 57 entries. It would have the added
bonus of being quite fast.

--
Ben.
Jun 15 '07 #18
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>If one
really needed an absolutely cast-iron, overflow-safe factorial
function, one would just use a look up table. Even in a future C with
256 bit integers, you'd only need 57 entries. It would have the added
bonus of being quite fast.
Until you build it on a system whose int is 512 bit ;-)
--
Programming is what happens while you're busy making other plans.
Jun 15 '07 #19
LOOKS FINE BUT IF FAILS TO WORK FOR n>12
WHAT ABOUT USING LINKED LISTS?

Army1987 wrote:
#include <limits.h>
#include <errno.h>
long factorial(int n)
{
long f = 1;
int i;
if (n < 0) {
errno = EDOM;
return n % 2 ? LONG_MIN : LONG_MAX;
}
for (i = 1; i <= n; i++) {
if (f LONG_MAX / i) {
errno = ERANGE;
return LONG_MAX
} else
f *= i;
}
errno = 0;
return f;
}
Fairly difficult?
Jun 15 '07 #20
Umesh <fr****************@gmail.comwrites:
WHICH COMPILER(S) DO YOU USE?

GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.

GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly
[...]

The above two paragraphs are an uncredited direct quote from a
Wikipedia article,
<http://en.wikipedia.org/wiki/C_(programming_language)>.

There's nothing wrong with quoting from outside sources, and the
quoted material happens to be correct, but failing to provide
attribution is rude and dishonest.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 15 '07 #21
Umesh <fr****************@gmail.comwrites:
LOOKS FINE BUT IF FAILS TO WORK FOR n>12
WHAT ABOUT USING LINKED LISTS?
[...]

Don't shout. (Writing in all-caps represents shouting.)

Don't top-post. We've explained this to you numerous times; you've
shown no evidence so far of being intelligent enough to understand it,
but we're prepared to be pleasantly surprised.

Be less obnoxious.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 15 '07 #22
Army1987 wrote:
"Umesh" <fr****************@gmail.comha scritto:
>WHICH COMPILER(S) DO YOU USE?

GCC and other C compilers now support many of the new features
of C99. However, there has been less support from vendors such
as Microsoft and Borland that have mainly focused on C++, since
C++ provides similar functionality improvement.

GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or
don't work correctly

Well, I see that at least you know how to copy and paste.
He also seems to have learnt the horrible habit of top-posting.

Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

--
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)
--
Posted via a free Usenet account from http://www.teranews.com

Jun 15 '07 #23
"Army1987" <pl********@for.itwrites:
"Keith Thompson" <ks***@mib.orgha scritto nel messaggio
news:ln************@nuthaus.mib.org...
[...]
>Here's another program that uses a macro to compute factorials:
[code snipped]
>>
The use of a macro is equally gratuitous, but at least this one
operates more usefully. On a system with 32-bit longs, either program
works only for arguments up to 12; using unsigned long rather than
long didn't add enough range to change that. With 64-bit longs, it
works for arguments up to 20. Neither version checks for overflow
(which would be fairly difficult to do)

#include <limits.h>
#include <errno.h>
long factorial(int n)
{
long f = 1;
int i;
if (n < 0) {
errno = EDOM;
return n % 2 ? LONG_MIN : LONG_MAX;
}
for (i = 1; i <= n; i++) {
if (f LONG_MAX / i) {
errno = ERANGE;
return LONG_MAX
} else
f *= i;
}
errno = 0;
return f;
}
Fairly difficult?
Well, sufficiently difficult than I was unwilling to take the time to
do it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 15 '07 #24
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>>If one
really needed an absolutely cast-iron, overflow-safe factorial
function, one would just use a look up table. Even in a future C with
256 bit integers, you'd only need 57 entries. It would have the added
bonus of being quite fast.

Until you build it on a system whose int is 512 bit ;-)
If you really need to compute factorials, chances are you'll need them
for arguments that won't fit in any integer type, even if you have
512-bit integers.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 15 '07 #25

"Mark McIntyre" <ma**********@spamcop.netha scritto nel messaggio
news:ug********************************@4ax.com...
On Fri, 15 Jun 2007 17:33:40 +0200, in comp.lang.c , "Army1987"
<pl********@for.itwrote:
>>
"Keith Thompson" <ks***@mib.orgha scritto nel messaggio
news:ln************@nuthaus.mib.org...
>>>
The use of a macro is equally gratuitous, but at least this one
operates more usefully.
...
>>>Neither version checks for overflow
(which would be fairly difficult to do)
(snip code)
>>Fairly difficult?

Remember, you're callling this via a macro.
#include <errno.h>
#define factorial(n) \
do { \
int n_ = n; \
long f = 1; \
int i; \
errno = 0; \
if (n_ < 0) \
printf("%d is negative, so it has no factorial\n", n_);\
else { \
for (i = 1; i <= n_; i++) { \
if (f LONG_MAX / i) { \
printf("%d is too large for its factorial "\
"to be computed\n", n_);\
errno = ERANGE; \
break; \
} \
else \
f *= i; \
} \
if (errno != ERANGE) \
printf("Factorial of %d is %ld\n", n_, f);\
} \
} while (0) /*I'm not saying that it doesn't suck...*/
Jun 15 '07 #26

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.caha scritto nel messaggio
news:f4**********@canopus.cc.umanitoba.ca...
In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>>If one
really needed an absolutely cast-iron, overflow-safe factorial
function, one would just use a look up table. Even in a future C with
256 bit integers, you'd only need 57 entries. It would have the added
bonus of being quite fast.

Until you build it on a system whose int is 512 bit ;-)
#include <limits.h>
#include <errno.h>
long factorial(int n)
{
static long table[13] = { 1, 1, 2, 6, 24, 120, 720, 5040,
40320L, 362880L, 3628800L, 39916800L, 479001600L };
int i;
long f = table[12];
if (n < 0) {
errno = EDOM;
return n % 2 ? LONG_MIN : LONG_MAX;
}
if (n < 13) {
errno = 0;
return table[n];
}
for (i = 13; i <= n; i++) {
if (f LONG_MAX / i) {
errno = ERANGE;
return LONG_MAX;
} else
f *= i;
}
errno = 0;
return f;
} /*rewrite this eliminating multiple returns if you feel like it*/
Jun 15 '07 #27

"Keith Thompson" <ks***@mib.orgha scritto nel messaggio
news:ln************@nuthaus.mib.org...
Umesh <fr****************@gmail.comwrites:
>WHICH COMPILER(S) DO YOU USE?

GCC and other C compilers now support many of the new features of C99.
However, there has been less support from vendors such as Microsoft
and Borland that have mainly focused on C++, since C++ provides
similar functionality improvement.

GCC, despite its extensive C99 support, is still not a completely
compliant implementation; several key features are missing or don't
work correctly
[...]

The above two paragraphs are an uncredited direct quote from a
Wikipedia article,
<http://en.wikipedia.org/wiki/C_(programming_language)>.

There's nothing wrong with quoting from outside sources, and the
quoted material happens to be correct,
and it happens to be relevant to the point, and the poster happens
to understand why it is and what it means...
but failing to provide
attribution is rude and dishonest.

Jun 15 '07 #28
Keith Thompson <ks***@mib.orgwrites:
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
>In article <87************@bsb.me.uk>,
Ben Bacarisse <be********@bsb.me.ukwrote:
>>>If one
really needed an absolutely cast-iron, overflow-safe factorial
function, one would just use a look up table. Even in a future C with
256 bit integers, you'd only need 57 entries. It would have the added
bonus of being quite fast.

Until you build it on a system whose int is 512 bit ;-)

If you really need to compute factorials, chances are you'll need them
for arguments that won't fit in any integer type, even if you have
512-bit integers.
Sorry, I meant that the result, not the argumement, won't necessarily
fit in any integer type.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 15 '07 #29
On 15 Jun 2007 at 16:34, CBFalconer wrote:
He also seems to have learnt the horrible habit of top-posting.

Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

--
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/ (taming google)
<http://members.fortunecity.com/nnqweb/ (newusers)
--
Posted via a free Usenet account from http://www.teranews.com
You seem to have learnt the horrible habit of posting 9-line double
signatures.

Please do not post 9-line double signatures. Your signature should be at
most 4 lines long.

--
CBFalconer: breathtaking hypocrite or insidious troll?
Jun 15 '07 #30
On Fri, 15 Jun 2007 21:46:47 +0200, in comp.lang.c , "Army1987"
<pl********@for.itwrote:
>
"Mark McIntyre" <ma**********@spamcop.netha scritto nel messaggio
news:ug********************************@4ax.com.. .
>Remember, you're callling this via a macro.
#include <errno.h>
#define factorial(n) \
(snip macro that could suck bowling balls through a drinking straw)
>} while (0) /*I'm not saying that it doesn't suck...*/
*phew*
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 15 '07 #31

"Mark McIntyre" <ma**********@spamcop.netha scritto nel messaggio
news:8v********************************@4ax.com...
On Fri, 15 Jun 2007 21:46:47 +0200, in comp.lang.c , "Army1987"
<pl********@for.itwrote:
>>
"Mark McIntyre" <ma**********@spamcop.netha scritto nel messaggio
news:ug********************************@4ax.com. ..
>>Remember, you're callling this via a macro.
#include <errno.h>
#define factorial(n) \

(snip macro that could suck bowling balls through a drinking straw)
>>} while (0) /*I'm not saying that it doesn't suck...*/

*phew*
Here is why I don't usually ever use the do { } while (0) trick.
If I cannot write a macro that expands to an expression, not even
abusing commas, &&s, ||s, ? :s and parentheses, then I write a
function. (And if I cannot write a macro that does not evalue each
argument exactly once, where each argument and the whole expression
is surrounded by as many parentheses as possibly ever needed, which
does not try to assign to or use the address of arguments etc.,
then I don't use lowercase in its name.)
Here I wanted to show that writing a macro that writes the
factorial of a number to stdout (other than
#define PRINT_FACT(n) (printf("Factorial of %d is %ld," (n),\
factorial(n)))
) albeit possible, isn't worth the trouble.
Jun 16 '07 #32
"Umesh" writes:
Which compiler do you use?
It's working fine in TC++ 3/4.5 & VC++ 6
Umesh, if you want to hold a conversation with someone via Usenet instead of
E-mail, you and your correspondent should both post to
alt.anonymous.messages, that's what the group is *for*. Doing so will avoid
the need for the rest of us to be subjected to the fragmentary, disorganized
thoughts you have from time to time.

Do you understand that "you" refers to one particular person, and not a
group of people collectively? Do you realize that you have not identified
that person?
Jun 16 '07 #33
In article <5d*************@mid.individual.net>,
osmium <r1********@comast.netwrote:
>Do you understand that "you" refers to one particular person, and not a
group of people collectively?
Incorrect. "You" may be a single person, or it may be a group of
people being addressed collectively, or it may be a generic "somebody"
(though I believe that "one" is the english-pedant-correct word to use
for that last one).
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca

Wow, I actually I agree with you on some things.
--Jesse Rodgers in uw.general
Jun 16 '07 #34
On Sat, 16 Jun 2007 22:06:45 +0000 (UTC), dj******@csclub.uwaterloo.ca
(Dave Vandervies) wrote:
>In article <5d*************@mid.individual.net>,
osmium <r1********@comast.netwrote:
>>Do you understand that "you" refers to one particular person, and not a
group of people collectively?

Incorrect. "You" may be a single person, or it may be a group of
people being addressed collectively, or it may be a generic "somebody"
(though I believe that "one" is the english-pedant-correct word to use
for that last one).
In formal usage you should use "one" but in informal usage one should use
"you".
Jun 16 '07 #35

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
0
by: Daron S. Lowell | last post by:
I need to be able to obtain the dimensions of some graphics files. Most of what I have found in this group seems to indicate loading the files into a form, then obtaining the dimensions form a...
19
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with...
11
by: bill | last post by:
I recently worked with a piece of code where dereferencing the pointer was too slow, and I was able to achieve a nearly 2x speed-up by replacing a local array of size 8 with 8 local variables. (*x...
4
by: thinktwice | last post by:
i have just made a test project :(win32 console) //file : func.h #ifndef _FUNC_H_ #define _FUNC_H_ void func1() { return; };
2
by: Jack | last post by:
I have a chunk of code that loads a few dozen function pointers into global variables. I'm concerned with unused memory consumption. What if the client only needs to use one or two functions? Then...
18
by: mdh | last post by:
May I ask the following. By K&R's own admission, the example used to describe function pointers is complex ( on P119). In addition, the use of casts has been stated by some on this group as...
16
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.