printf.c and C

This is a discussion on printf.c and C within the C Programming forums, part of the General Programming Boards category; Hi, I've written some code for C. I am no expert but some C code seems NOT C!!! For example ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    printf.c and C

    Hi,

    I've written some code for C. I am no expert but some C code seems NOT C!!!

    For example the printf.c contains chinese C for me.

    I never learned those stuff like:

    _lock_str2(1, stdout);
    __try {


    What's up with all these underscores???

    Can someone tell me why this code is VERY different from what you learn in textbooks and where I can read more about it.


    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Things with double __ in them are reserved for the use of the compiler. So this is the implementation, which means it may very well be implementation- or OS-specific.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    _lock_str2 is a function...
    __try is... well, I can only guess that it's a compiler-specific implementation of the C++ try keyword.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    __try is somewhere between __half_assed and __best_effort
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    75
    where CAN I read more about this chinese C ?????

    Is there a book, web site.

    What is called, this chinese C?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't know what printf.c you're looking at (the GNU printf.c doesn't have __try in it that I can find). As mentioned, __try would have to be compiler-specific, so the proper place to read about it would be "your compiler's user's manual".

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    I can google for examples of _lock_str2 and its counterpart unlock. Can't seem to get at a manual though. I can guess that it locks the stream while input/output is performed.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Yoda: "__do, or __do_not. There is no __try."

    Sorry, couldn't resit the temptation.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    Note that function calls (user-defined functions!) aren't covered by any C book. It's a function, so you have to understand what it does, just as you would have to in your own code.
    And it's not chinese C. It's perfectly fine C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    Extensible language...What ?

    Is C , C++ or Java extensible languages?

    What is an extensible language? I have the definition but no example so I don't understand.

    Wikipedia: Extensible programming is a term used in computer science to describe a style of computer programming that focuses on mechanisms to extend the programming language, compiler and runtime environment.

    Could you give me examples?

    How can you modify the compiler?

    Thanks.

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    You can write your own functions and data structures in C and your own operators in C++, so I'd call them extensible.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by jordanguyoflove View Post
    Is C , C++ or Java extensible languages?

    What is an extensible language? I have the definition but no example so I don't understand.

    Wikipedia: Extensible programming is a term used in computer science to describe a style of computer programming that focuses on mechanisms to extend the programming language, compiler and runtime environment.

    Could you give me examples?

    How can you modify the compiler?

    Thanks.
    I couldn't help but get a little chuckle out of this post. "Mom is our puppy dead? What about Grandma? What is dead?"

    >> How can you modify the compiler?

    Taking the question only losely, I will say you can modify the behavior of your compiler through compiler flags.

    Taking the question more literally, you would have to recompile the whole compiler.

  13. #13
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,658
    Quote Originally Posted by master5001 View Post
    Taking the question more literally, you would have to recompile the whole compiler.
    ... compilers are such wonderful black boxes.

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    You can write your own functions and data structures in C and your own operators in C++, so I'd call them extensible.
    I'd agree with "very flexible", but I don't think that C or C++ (or Java for that matter) counts as "extensible languages" as such. They are all languages that can do many things, including be used to write other languages and many other things. But strictly speaking, not extensible - you can't freely and simply (using the existing language definition) change the language itself - you can use existing language structures to do things that may not make much sense ( using % as an operator on strings to perform something like strtok(), perhaps?), but that's not, strictly speaking, changing the language as such - it is defined in the C++ language that operator% takes two parameters, and you can use that for whatever purpose you like (some things may make more sense than others, but that's a different matter altogether).

    In the sense of runtime, I guess that you can modify that in C or C++ - and of course, it's possible to extend the compiler - most vendors do, but those extensions only make it into the standard after many years.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

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