Speed consideration in (void)printf(..) 
Author Message
 Speed consideration in (void)printf(..)

Quote:

> Is there any speed advantage using

>    (void)printf("Hello");

> than

>    printf("Hello");

I doubt it.
--
"You call this a *C* question? What the hell are you smoking?" --Kaz


Sat, 25 May 2002 03:00:00 GMT  
 Speed consideration in (void)printf(..)

Quote:

> Is there any speed advantage using
>    (void)printf("Hello");
> than
>    printf("Hello");
> ?
> I already know the `(void)' prevents generating warning by lint.

If you are not using the return value from the function call, the two
forms are effectively equivalent.

Quote:
> But how about the speed?
> Is there any speed advantage?

Probably not, but this is an optimization question, which is outside
the purview of ANSI C.  Check in your compiler's newsgroup.

Regards,
Psy
http://www.nothingisreal.com

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 25 May 2002 03:00:00 GMT  
 Speed consideration in (void)printf(..)
Greeting.

Is there any speed advantage using

   (void)printf("Hello");

than

   printf("Hello");

?

I already know the `(void)' prevents generating warning by lint.

But how about the speed?

Is there any speed advantage?

------------------------------------------------

Forgive my poor English :-)



Sun, 26 May 2002 03:00:00 GMT  
 Speed consideration in (void)printf(..)


Quote:
>Greeting.

>Is there any speed advantage using

>   (void)printf("Hello");

>than

>   printf("Hello");

>?

>I already know the `(void)' prevents generating warning by lint.

>But how about the speed?

>Is there any speed advantage?

Nothing within either of the ANSI standard mandates anything
about speed of any operation -- a conforming compiler could
make one or the other faster, or make both equally fast.

However, since the cast there really isn't doing anything,
I would expect that they would both be equally slow.

Three questions:

- Why are you concerned with speed?  Have you determined that
  your program is too slow, and it's too slow because of not
  putting in a (void) ?

- If you are so concerned with speed, why are you using printf?
  The time taken by your program will almost certainly be
  dwarfed by the time it takes to actually output the characters.

- Why are you using a broken version of lint that doesn't know
  that the output of printf is boring, and that it can be ignored
  without being an even minor concern?

--
poncho



Sun, 26 May 2002 03:00:00 GMT  
 Speed consideration in (void)printf(..)

Quote:

>Greeting.

>Is there any speed advantage using

>   (void)printf("Hello");

>than

>   printf("Hello");

>?

>I already know the `(void)' prevents generating warning by lint.

>But how about the speed?

>Is there any speed advantage?

Anything is possible since the C specification makes no requirements
on speed, but it's extremely unlikely.

John
--
John Winters.  Wallingford, Oxon, England.

The Linux Emporium - the source for Linux CDs in the UK
See http://www.linuxemporium.co.uk/



Mon, 27 May 2002 03:00:00 GMT  
 Speed consideration in (void)printf(..)

Quote:

> Is there any speed advantage using
>    (void)printf("Hello");
> than
>    printf("Hello");
> ?

No -- because printf has already been written and compiled and is in the
standard library. Whether you explicitly or implicitly ignore the value,
it'll still be returned. By casting it away, you're not stopping printf
from computing it. The compiler, when it compiles this, does not know
to change printf. You could get the source code and hack printf not
to compute the value it returns, but without looking I would bet that
the value is part of the integral parsing code for the format string
anyway. See Plauger's book for an implementation of printf, or libg
or something.

Scott



Mon, 27 May 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. void pointers considerations

2. (void)printf() vs. printf()

3. Re(2): Re(2): (void)printf() vs. printf()

4. Re(2): (void)printf() vs. printf()

5. from void (void*) to void (_cdecl*) (void*)

6. newbie and (void)printf..

7. printf("%p\n",(void *) ptr);

8. what's the difference between void main(void) and int main(void)

9. difference between void foo(void) and void foo()

10. replacing printf with my printf, then calling C lib's printf

11. Visual C++ 7 speed vs Visual C# speed

12. .NET speed vs COM speed

 

 
Powered by phpBB® Forum Software