writing an interpreter for this programming language - segmentation error

This is a discussion on writing an interpreter for this programming language - segmentation error within the C Programming forums, part of the General Programming Boards category; This is not a problem. A plain 0 in a pointer context is treated as a null pointer. Other equivalent ...

  1. #16
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,323
    This is not a problem. A plain 0 in a pointer context is treated as a null pointer. Other equivalent forms are treated the same way, such as the expression (!file) which is equivalent to (file != 0), which is a valid comparison against a null pointer.
    I did say that it might not be a problem - I was just saying that the value of NULL is implementation defined; it doesn't have to be zero.

    References
    C11 - 7.19 #3
    C99 - 7.17 #3
    C89 - 4.1.5

    I was shocked as you when I learnt that I was making non-portable code by looking for !fp -
    Fact - Beethoven wrote his first symphony in C

  2. #17
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    I made a typo in my last post: (!file) is equivalent to (file == 0), NOT to (file != 0).

    Both forms are valid (and portable) to compare the file pointer against a null pointer.

  3. #18
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,323
    Both forms are valid (and portable) to compare the file pointer against a null pointer
    From all three standards

    C11
    NULL
    which expands to an implementation-defined null pointer constant
    [edit]
    I've found something that will fix the confusion - I was wrong, because the null pointer constant is defined as

    An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
    [/edit]
    Last edited by Click_here; 11-11-2012 at 10:00 PM.
    Fact - Beethoven wrote his first symphony in C

  4. #19
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Using ASCII vs numbers does not have any performance impact. They are compiled to the exact same machine code.

    Even if it does, don't optimize prematurely. Don't optimize if you don't need to. Don't optimize unless the code is too slow, and you know exactly which part is too slow.

    In 99% of cases, code clarity is much more important.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creation of a Command Language Interpreter
    By Sicilian_10 in forum C Programming
    Replies: 18
    Last Post: 04-16-2010, 06:36 AM
  2. What Language are you writing in?
    By C-Compiler in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 12-24-2008, 10:51 AM
  3. Replies: 0
    Last Post: 04-06-2007, 04:55 PM
  4. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  5. Register tranfer language interpreter in C
    By Nutcasey in forum C Programming
    Replies: 18
    Last Post: 01-06-2004, 12:11 PM

Tags for this Thread


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