Thread: Making my own version of the scanf() version

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Cwmbran, South Wales
    Posts
    18

    Making my own version of the scanf() version

    Hi guys,

    This is sort of two questions in one really XD.

    I'm trying to make an OS using C. Which is a real challenge as I'm more of a C++ kinda guy, anyway.

    How would I be able to create a scanf() type function? The reason I'm asking is because, as you may know, when making an OS you can't include system headers ( you know the #include < > ones ). Is there a way of doing this without the system headers?

    And a second, less important question is, how would I be able to incorporate C++ into the C kernel? I.e. make a c++ function, and then call it from within the C main() function? ( If this can be answered then it could make my life easier with the scanf problem as I could use std::cin instead. ).

    Thanks in advance.

    Jamie.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Writing the C++ standard libraries is very likely much harder than writing the C standard libraries.

    I suggest reading stuff in OSDev.org &bull; Index page forums.
    http://wiki.osdev.org/Main_Page

    Tim S.
    Last edited by stahta01; 04-29-2012 at 02:35 PM. Reason: spelling
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I'm trying to make an OS using C. Which is a real challenge as I'm more of a C++ kinda guy, anyway.
    O_o

    How would I be able to create a scanf() type function?
    O_o

    Is there a way of doing this without the system headers?
    O_o

    If this can be answered then it could make my life easier with the scanf problem as I could use std::cin instead.
    O_o

    You have no business making a kernel.

    You are so incredibly not ready for the task you've set yourself.

    Pull your head from your ... and read a book on programming.

    Soma

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    in the C++ file you declare your function 'extern "C" <function declaration>'. this tells the C++ compiler to use C linkage. then a C program can call it. it has to be a plain old function and it can't use any C++ features in the function declaration.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by dmh2000 View Post
    in the C++ file you declare your function 'extern "C" <function declaration>'. this tells the C++ compiler to use C linkage. then a C program can call it. it has to be a plain old function and it can't use any C++ features in the function declaration.
    Link about this.
    [32] How to mix C and C++ Updated! , C++ FAQ

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcc Version
    By kris.c in forum Tech Board
    Replies: 2
    Last Post: 07-04-2006, 09:37 AM
  2. Dev C++ version 4
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 12-19-2004, 12:55 PM
  3. version?
    By moi in forum Windows Programming
    Replies: 3
    Last Post: 11-27-2002, 05:10 AM
  4. GLH Version 1.4
    By Eber Kain in forum Game Programming
    Replies: 0
    Last Post: 11-14-2001, 01:44 AM

Tags for this Thread