Thread: The $ operator?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    230

    The $ operator?

    Hi,
    I've been seeing this operator ($) a lot in different sources. What does it do? I searched google and wiki but didn't find any info about it.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I've never seen an operator $ - there are some compiler extensions to support $ as part of the identifiers e.g. you could have a symbol my$var - a bit like _ in that sense.

    Edit: are you perhaps referring to the $ used in shell-scripts and PHP to indicate a variable? e.g
    Code:
    $foo=7;
    in php.

    --
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    This is one of the places where I saw it:
    Code:
    $ cat foo.c
    #include <stdio.h>
    struct empty {
    };
    int main ( ) {
        printf( "&#37;ld\n", sizeof(empty) );
        return 0;
    }
    
    $ gcc foo.c
    foo.c: In function `main':
    foo.c:5: error: `empty' undeclared (first use in this function)
    foo.c:5: error: (Each undeclared identifier is reported only once
    foo.c:5: error: for each function it appears in.)
    $ g++ foo.c
    $ ./a.exe
    1
    I understand the part where he compiles, but I don't understand the one on the first line.

    Thanks anyway.
    Last edited by Abda92; 11-20-2007 at 10:15 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh, that is not actually part of the code. It is just the shell prompt.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That's like the "C:\>" in a Windows/DOS command shell.

    --
    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.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    ooooh, OK. Thanks. I've never seen "cat" being used in the shell.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Abda92 View Post
    ooooh, OK. Thanks. I've never seen "cat" being used in the shell.
    Where have you been using it then?

    --
    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.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Nowhere. I didn't even know it exists! I've used linux for a while, but I never needed it. What does it do?

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Concatenate files together and print them to the command line (or wherever you redirect the output to). Since there is only one file specified, it just prints that file's content.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Good thing the guy that made the example wasn't running as root, otherwise you'd be trying to find a #cat preprocessor directive!

  11. #11
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    "cat" is equivalent to "type" in a DOS box (but can do a lot more)

    Todd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM