Thread: functions with preceeding underscores

  1. #1
    sockets mad
    Join Date
    Mar 2002
    Posts
    126

    functions with preceeding underscores

    Hi,

    I've got a quick question. I was looking at the vsnprintf function, which on UNIX OSs is simply vsnprintf where-as on Windows it is defined as _vsnprintf. Why is it that this function, and some others have a preceeding underscore in Windows?

    Thanks,

    Daniel
    C/C++ Support IRC Channel

    Server: irc.dal.net Channel: #csupport

    Come along and help make it a great resource for the community.

  2. #2
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    only reason i could think of is to have less chance of conflicting with a user function

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Though I can't find the immediate reference, names beginning with an underscore and a capital letter, or two underscores, are reserved. A quick few hits give you topics on name space pollution (link), and a few (link) hits (link) on general naming schemes.

    I'm sure someone'll be along shortly to quote the standard. But since I don't have it around, I'll leave that to them.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    thanks quzah.

    Does this mean that in my code I'm safe to do the following?

    Code:
    #ifdef _WIN32
    #define vsnprintf _vsnprintf
    #endif
    and then just use vsnprintf in all my code, whether it be Windows or *nix?

    Daniel
    C/C++ Support IRC Channel

    Server: irc.dal.net Channel: #csupport

    Come along and help make it a great resource for the community.

  5. #5
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    yeah, as long as vsnprintf is not defined already.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM