The $ operator?

This is a discussion on The $ operator? within the C Programming forums, part of the General Programming Boards category; Hi, I've been seeing this operator ($) a lot in different sources. What does it do? I searched google and ...

  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
    22,275
    Oh, that is not actually part of the code. It is just the shell prompt.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,275
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Katy, Texas
    Posts
    2,309
    "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, 10:42 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03: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-07-2003, 12:51 AM

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