473,327 Members | 1,976 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,327 software developers and data experts.

Clarification regarding #include declarations.

Hi,
I was writing this C++ program wherein I used an include statement
like -
#include <iostream.h>

I was told by my co-worker that this form of including a file is
deprecated and should not be used, instead it ought to be something
like

#include <iostream>

And this ought to be the standard way of including files.
So does this imply that , my program should not have any header files
of the following type , something like -
#include <myclassdef.h>

...

is that deprecated / alternate syntax of #include that achieves the
same thing.

- Rakesh
Jul 22 '05 #1
7 1660
Rakesh wrote in news:3e**************************@posting.google.c om in
comp.lang.c++:
Hi,
I was writing this C++ program wherein I used an include statement
like -
#include <iostream.h>

I was told by my co-worker that this form of including a file is
deprecated and should not be used, instead it ought to be something
like
Its not deprecated, deprecated means something that was/is standard
that will nolonger be standard at some point in the future.

There never was a *standard* header <iostream.h>.

#include <iostream>
This is part of the standard library, and is what you should use.

And this ought to be the standard way of including files.
So does this imply that , my program should not have any header files
of the following type , something like -
#include <myclassdef.h>

No, this should be:

#include "myclassdef.h"

Only use the <> syntax for header's that come with your implementation
(aka compiler), including the headers that are part of the Standard
library.

Also, what file extension you give *your* files is up to you, .h, .hpp
and .hxx are common. Some OS's allow your files to be assosiated with
a particular application based on the files extension (an editor say)
so you should probably use one if these.
...

is that deprecated / alternate syntax of #include that achieves the
same thing.


The headers <stdio.h> etc, inhereted from C are *deprecated*, you should
use <cstdio> etc, instead, which only supply the standard library in
namespace std:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
Rob Williscroft wrote:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Personally I'd deprecate any use of printf/scanf-related functions.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #3
Kevin Goodsell wrote in news:v_zgc.19887$A_4.14887
@newsread1.news.pas.earthlink.net in comp.lang.c++:
Rob Williscroft wrote:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Personally I'd deprecate any use of printf/scanf-related functions.


Well I've never used scanf, so I really don't care,
remove it, depricate it, enhance it, I'll never notice :).

printf can be safe, gcc has been doing this for years and I
got the impression from a recient comp.lang.c x-post that
many in the C world consider this to be something that
should be expected from a a High Quality(tm) implementation.

In the next standard we may get templates function's with
an unlimited number of arguments (an equivalent of , ...),
so we may be able to fix the "type saftey" problem with
std::printf().

Even better we can write:

template < typename T, template Args ... >
std::shared_ptr< T > std::shared_new( Args );

template < typename T, template Args ... >
std::auto_ptr< T > std::auto_new( Args );

and can depricate new and delete :). (*)

Rob.
--
*) Only /half/ joking.
Jul 22 '05 #4
Rob Williscroft wrote:

printf can be safe, gcc has been doing this for years and I
got the impression from a recient comp.lang.c x-post that
many in the C world consider this to be something that
should be expected from a a High Quality(tm) implementation.
GCC's printf() (and scanf()) format checking is cool, but it's not a
general solution. It can't possibly check all formats, because formats
are not necessarily known at compile time. We don't see a lot of
run-time generated format strings, but it's the only way to do some
things (unless you drop printf()/scanf() completely and roll your own,
which isn't necessarily a bad idea). The obvious example, I think, is a
%s or %[ scanf() format where the corresponding char array argument is
dynamically allocated, or of unknown (at compile-time) size for other
reasons, such as being the argument to a function.

I can't think of an obvious printf() example -- field widths can be
specified with a variable in printf() -- so maybe the situation isn't as
bad there. Of course, even if it's not *necessary* to use dynamic format
strings for a particular situation, that doesn't mean somebody won't use
them.

In the next standard we may get templates function's with
an unlimited number of arguments (an equivalent of , ...),
so we may be able to fix the "type saftey" problem with
std::printf().


Overloading + chaining (overloading being the key part, chaining is just
for convenience), like in the standard streams, seems like the "right"
solution to me. I don't know about this.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #5
Kevin Goodsell <us*********************@neverbox.com> wrote in message > >
Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Thanks for letting me know a different syntax.
Personally I'd deprecate any use of printf/scanf-related functions.


I am a little bit confused here. You mean to say, they are not
supposed to be used ( is it that we should use only - cin , cout or
something similar to that).

- Rakesh.
Jul 22 '05 #6
Rob Williscroft <rt*@freenet.co.uk> wrote in message news:<Xn**********************************@130.133 .1.4>...

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Thanks for letting me know that, Rob.

- Rakesh.
Jul 22 '05 #7
Rakesh wrote:
Kevin Goodsell <us*********************@neverbox.com> wrote in message > >

Personally I'd deprecate any use of printf/scanf-related functions.

I am a little bit confused here. You mean to say, they are not
supposed to be used ( is it that we should use only - cin , cout or
something similar to that).


I'm saying that I would recommend not using them. They are very
difficult to use correctly, and your compiler probably won't tell you
when you use them wrong.

Anything that defeats type-checking is best avoided, particularly when
better options are available (such as standard streams classes).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #8

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

Similar topics

2
by: Rakesh | last post by:
Hi, I was writing this C++ program wherein I used an include statement like - #include <iostream.h> I was told by my co-worker that this form of including a file is deprecated and should...
3
by: siddharth_jain_1 | last post by:
Hello, 1) what do header files contain exactly? Do they just contain the variable declarations, typedefs and function prototypes? 2) taking the example of iostream.h: it contains the...
3
by: John Ratliff | last post by:
I have a program, the classes that belong to it all belong to a special namespace I created for them. This had lead to a minor issue I don't quite understand. For some reason, when I return a...
77
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
36
by: Viken Karaguesian | last post by:
Hello all, I just need confirmation on the subject of font size and its inheritance. Take this example: body { font-family: arial; font-size: 95%; }
7
by: James | last post by:
Hello, First off, I know this code will not compile and am not asking for someone to solve it for me. What I am asking is from the code below, how does one first define an array as a...
3
by: sam_cit | last post by:
Hi Everyone, I have seen in some project where functions are declared as extern, what is the possible reason to do this? To my best understanding, if some other file wan't to invoke this...
2
by: mattmao | last post by:
My code works fine with this command: gcc mycode.c It is compiled and runs just as I wanted. But since my assignment has a specific restriction, my code must go through this: gcc...
9
by: ramsatishv | last post by:
Hi, If I include a ".h" file for multiple times, will it increase my program size?? Regards Ram.
5
by: Philip Potter | last post by:
I have a somewhat flippant question regarding undefined behaviour. Does an operation which invokes undefined behaviour affect the whole program, or are earlier statements guaranteed to execute...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.