Thread: value of stdin (not zero?)

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    Question value of stdin (not zero?)

    Hi,

    I have this x86 assembly code (I use it to flush the input away)

    pushl stdin
    pushl $STRING_LEN
    pushl $long_string
    call fgets

    (it seems to works, because I don't have a segmentation fault)

    but if I change pushl stdin with pushl $0, then I get a segmentation fault.

    does this mean that stdin is not zero?
    is the value stdin different on different computers?

    (the program is run on a laptop)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > but if I change pushl stdin with pushl $0, then I get a segmentation fault.
    Because that's like saying
    fgets( long_string, STRING_LEN, NULL );

    stdin is not a NULL pointer.

    This is not the same as descriptor 0 which is stdin when using the POSIX API.
    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.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I remember writing some assembly code just recently where I needed at least one of the three standard FILE *'s.

    You need to find the variable that represents all of the FILE *'s. The following code worked with Borland's assembler where I used fprintf() to print out an error message to stderr.

    Obviously your situation will probably be much different, but the idea is the same. Find the way the standard FILE *'s are organized for your assembler/compiler and import them into your program.

    Code:
    extern __streams:near
    
    ....
    
    push offset szMemErr
    push dword ptr [__streams + 8]
    call _fprintf
    add esp, 8
    Joys of assembly programming...

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    16
    oeps, I thought file descriptor is the same as file pointer,

    thank you,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking stdin for input
    By hawaiian robots in forum C Programming
    Replies: 7
    Last Post: 05-19-2009, 09:06 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 2
    Last Post: 07-12-2008, 12:00 PM
  4. Question About Reading Lines from stdin
    By Zildjian in forum C Programming
    Replies: 7
    Last Post: 11-12-2003, 05:45 AM
  5. stdin question
    By oomen3 in forum C Programming
    Replies: 6
    Last Post: 02-19-2003, 02:52 PM