C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-18-2006, 11:01 AM   #1
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
Question C++ std routines

Are C++ stnadard routines like std::cout wrriten using C liberary functions like fgets()?
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Old 07-18-2006, 12:00 PM   #2
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,201
cout is an object representing an output stream, so a function like fgets has no real place there. What you may be thinking of is cin.getline, which has a couple of signatures. This one:

istream& getline( char* buffer, streamsize num, char delim );

acts the most like fgets, so it's probably implemented that way.
whiteflags is offline   Reply With Quote
Old 07-18-2006, 12:37 PM   #3
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,661
>Are C++ stnadard routines like std::cout wrriten using C liberary functions like fgets()?
Possibly, but not likely. It's easier (not really, but it's *better*) to work through a lower level API than to use a middle man.
__________________
My best code is written with the delete key.
Prelude is offline   Reply With Quote
Old 07-18-2006, 01:08 PM   #4
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
[>>>>>>>>>>>>>>>>>>>>>>>>>>>EDITED<<<<<<<<<<<<<<<<< <<<<<<<<]
I read in msdn that fgets() and similar functions are standard in C Run-Time liberary. The CRT functions should be platform independent (Am I right?), so the lowest level of platform independent functions are fgetc(), _putw(), _getch(), _setmode(), etc. Am I right?
If C++ std liberaries like iostream has their own low level rutines and does not use C rutines, then why msdn Run-Time liberary reference is full of C rutines?

Another point: When we use Win32 API for creating a file for example. Some very low level rutines that are written by microsoft and are in kernel32.dll for example execute. These low level rutines does not use C or C++ std libraries to do their job. Am I correct?
Now if we imagine that Windows don't prophibit us from executing low level rutines and I want to write a program that formats a hard drive, am I beyond the OS hardware abstraction layer?
How Partition Magic formats a drive for example? What rutines does it use?

If you feel my questions are stupid or confuzing please tell me to explain more. It is very important for me to find the correct answers.
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC

Last edited by siavoshkc; 07-19-2006 at 11:10 AM.
siavoshkc is offline   Reply With Quote
Old 07-19-2006, 10:42 AM   #5
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
> Maybe I should ask how fgets() works? What rutines does it use?
Whatever the current platform has to offer probably.

Consider the std:: the nice level concrete on which you build your house.

Underneath, there is the whole jaggy mess of the current platform, but you don't need to know about that. In some places it can be quite thin, but in other places it could be much thicker.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-20-2006, 10:08 PM   #6
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
I've edited my last post. So please read it again.
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Old 07-21-2006, 12:43 AM   #7
Registered User
 
Join Date: Jan 2005
Posts: 7,137
Platform independence in C++ just means that the interface will be the same across platforms. You can find the same functions that will do the same thing on any platform that has a conforming compiler. That does not mean that the functions are all implemented in the same way.

So the C and C++ standard libraries are both platform independent in their interfaces, but they both can be (and are) implemented differently on different platforms. Sometimes they are implemented in terms of each other, sometimes they are implemented with platform specific functions, sometimes they are implemented with platform specific assembly.

The C runtime library is available to C++ programmers if they choose to use it, which is why it is covered in MSDN, just like the C++ standard library.
Daved is offline   Reply With Quote
Old 07-21-2006, 07:00 AM   #8
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
OK. So for example when I use std::cin.get() in my code, the real code that will be replaced by a linker or (if its body is in a DLL and will be executed in RunTime) can be different in each platform. The standard is only for the arguments, return value and the duty of the function, the body can be different.
Am I correct?

How Partition Magic formats a drive for example? How OS let him do its job?
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Old 07-21-2006, 07:36 AM   #9
(?<!re)tired
 
Mario F.'s Avatar
 
Join Date: May 2006
Location: Portugal
Posts: 5,220
That is correct... in a way. It's at compile-time, not linking-time.

In the context of this discussion, i'm defining a C++ implementation as the combination of the compiler, linker and standard library (including the STL). Your implementation is portable if it conforms to the ISO C++ specifications. These specifications rule the language syntax and how the entities of the standard library should be presented to the user (we, the coders).

If an implementation changes these rules, it is not portable. For instance, if the syntax for a function declaration was altered by some implementation to function_name return_type(arglist,...); instead of the ISO defined return_type function_name (arglist,...);, this implementation would not be portable across other implementations.

On another implementation that conformed to ISO C++, that change would be caught at compile time and flagged as an error.

If the implementation overloaded getline() to include yet a new declaration with different parameters than those already defined in the standard library, the same would happen if the user decided to code with the new getline function and compile his code on another implementation.

However, despite being not portable across implementations, it could still be portable across systems. That implementation (assuming it was a Win32 one) could have a corresponding one for Linux, and Solaris, and DEC,...

That level of portability (portability across systems) is achieved by the implementation provider in how he coded the standard library (STL included). It is obvious that a std::cout cannot work the same way in windows, linux, Macintosh,... However, to the user it must look like so. Regardless of the system the user is coding for, std::cout syntax must be the same. The code that implements std::cout, on the other hand, is necessarily different.

But the code of std::cout is "added" at compile time. Not linking time.
__________________
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.


Mario F. is offline   Reply With Quote
Old 07-21-2006, 08:18 AM   #10
Registered User
 
Join Date: Aug 2005
Posts: 1,265
>>How Partition Magic formats a drive for example? How OS let him do its job?

Partition Magic does not use either C or C++ standard functions for that because there are no such standard functions. It will have to go directly to the os api system calls, such as win32 api functions. I don't know which specific functions because I've never attempted to format a drive in a win32 program. Those os-specific functions can be called just like any of the standard c or c++ functions, just include the correct header file(s) and libraries. For win32 api functions, see www.msdn.microsoft.com or your compiler's online help files for win32 api functions.

Last edited by Ancient Dragon; 07-21-2006 at 08:24 AM.
Ancient Dragon is offline   Reply With Quote
Old 07-21-2006, 11:38 AM   #11
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
Quote:
But the code of std::cout is "added" at compile time. Not linking time.
Why at compile time? std::cout has external linkage and should be linked after compilation.

If I foun out correctly there are some functions in WinIoCtl.h that can do such things. Is it possible to write own code for formatting and partitioning?
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Old 07-21-2006, 12:29 PM   #12
Registered User
 
Osaou's Avatar
 
Join Date: Nov 2004
Location: Stockholm, Sweden
Posts: 69
Yes it is. ASM is your friend and worst nightmare.
Osaou is offline   Reply With Quote
Old 07-21-2006, 01:04 PM   #13
(?<!re)tired
 
Mario F.'s Avatar
 
Join Date: May 2006
Location: Portugal
Posts: 5,220
The linkage type regulates the visibility of a name. Not if that name is added during compile or link-time.

External linkage names are those names that are visible from every translation unit of a program (global objects, extern const objects, classes...)

An Internal linkage name is a name that is local to the translation unit where it was declared (non extern const objects, names declared inside namespaces, static objects,...).

No linkage objects are all those names local to the scope in which they were declared, but not visible across the entire translation unit (local variables, enumerators declared inside a function, classes defined inside a function,...)
__________________
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.


Mario F. is offline   Reply With Quote
Old 07-21-2006, 04:02 PM   #14
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
OK maybe I should use the term external refference. But I thought std::cin is in a lib and should be linked by linker to .obj. Or is in a DLL.
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Old 07-22-2006, 11:57 AM   #15
System Novice
 
siavoshkc's Avatar
 
Join Date: Jan 2006
Location: Tehran
Posts: 1,074
Yoy know, cin.get() is not an intrinsic function. I am now really confuzed.
If I am wrong please correct me (above post).
__________________
Microsoft Visual Studio 2008 Professional (On Microsoft Windows XP SP2)

Learn the language before using it. (C++ Books and C Books)
Read the FAQ before making a problem.
Then make a Google and Forum search.

My code painter new version Version 0.97 DOWNLOAD NOW! (Let the pop up, pop!)

SiavoshKC
siavoshkc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why std:: and not using namespace std? swappo C++ Programming 4 07-03-2009 03:10 PM
std:: or namespace std C-+ C++ Programming 16 12-04-2007 12:30 PM
Builder 5 v's bcc32.exe sononix C++ Programming 3 08-17-2004 10:17 AM
Site tutorials Aalmaron C++ Programming 20 01-06-2004 02:38 PM
Special Allegro Information TechWins Game Programming 12 08-20-2002 11:35 PM


All times are GMT -6. The time now is 09:51 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22