Thread: Viewing souce code in Visual C++

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    2

    Viewing souce code in Visual C++

    Here is my second question:

    Using Visual C++, how can the view the source code for all the built in functions in C++.

    Example, in the class string, viewing the strcpy or strlen code (function definition) i.e the actual code written for the function?

    I tried looking at MSDN library but not sure where and what to search for.


  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you download the microsoft SDK, then you get the source to a lot of the C runtime libraries. Other than that, I think you're out of luck as far as the library source code goes.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Yes, as far as I know the code is written. Do a find on your computer for "cstring" or whatever header you wanted to look at, and I'm pretty sure you'll find what you want. Otherwise, you can:

    1) Create a program that uses the function you want to look at
    2) Run it in the debugger, and as you get to the function call, click on "step into" instead of "step over"
    3) Keep hitting "step into" until you end up at the function definition (very very painful and slow).

    Otherwise, in MSVC 2005 (not sure about other versions), call the function/macro/variable in your code somewhere, then select it, right-click on it and click "Go to definition".
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    this question got me thinking

    how does the debugger access the code if it's already compiled? I mean, I can see how it accesses the headers... but the actual C libraries? Does it actually go through them as well?

    On my debugger (MS VC++2003.net) if I tell it to 'step into' a sin() function from the cmath header, it doesn't do anything. Does that mean it can't?

    If I step into a cout object, it eventually reaches an asm file. But wouldn't that already be compiled?

  5. #5
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Usually all you will see in the header files are the prototypes and class definitions. And in many cases class definitions in the headers are actually proxy classes to protect proprietary information of the original classes.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Hmm you're right, pretty much all you can see is the headers. What I was thinking of was the bug-fixes on dinkumware.com for MSVC 6, which require you to modify the implementation's code. In particular, what I'm referring to is the getline() in <istream> bugfix. However, the reason you can see the 'code' in it is because it deals with templates, which requires that the definition be in the header (although from what Scribbler said, perhaps it isn't even the 'real' class definition?). It's pretty ugly anyway, probably to discourage you from going through it.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Lightbulb Open Source...

    You can't see Microsoft's implementation, but you can look at some open source examples, such as the various GNUs, or Watsom. Take a look at TheFreeCountry.com. They have a list of free compilers. Some are open source.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Weird errors in code
    By sirSolarius in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2003, 09:55 AM
  3. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  4. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM