Thread: Unofficial extensions to C, structs with functions, does that exist?

  1. #46
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    Quote Originally Posted by Elysia View Post
    How does that make sense? What do you imagine a function being a collection of?
    Nothing. But I can imagine a function will occupy more than one location in memory. Am I wrong?

  2. #47
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    > Am I wrong?
    Yes, unless it is inlined by the compiler. The inline specifier can be ignored, so it doesn't guarantee inlining.

  3. #48
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    Not sure I understand..doesn't the inline specifier ask the compiler to replace the function call with the body of the function instead?

  4. #49
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by CSaw View Post
    Nothing. But I can imagine a function will occupy more than one location in memory. Am I wrong?
    Yes. A function exists only in one place in memory. There are never two identical functions on different places. That would defeat the purpose of a function.

    Quote Originally Posted by CSaw View Post
    Not sure I understand..doesn't the inline specifier ask the compiler to replace the function call with the body of the function instead?
    Or in the case of inlining, the compiler puts the contents of the function (or the body if you will) in place of the function call. So in that case, it exists nowhere.
    Although, granted, I don't know what happens if you try to get a function pointer from a function that can be inlined. Either the function will never be inlined or it will be inlined where possible but remain in memory.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #50
    Registered User
    Join Date
    Jul 2010
    Posts
    33
    Quote Originally Posted by Elysia View Post
    Yes. A function exists only in one place in memory. There are never two identical functions on different places. That would defeat the purpose of a function.
    What I meant was that, like an array exists as a block of contiguous memory, so must a function? In other words a function takes up more than one address in memory does it not? ( as a function has to be bigger than an individual element, for example a character which only occupies one address)

    Sorry if I'm just confusing matters.

  6. #51
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, that cannot possibly be true. The array has one starting memory address where it takes up a number of contiguous bytes.
    But the array itself starts at the memory address X. Similarly, a function does so, as well. What you are implying is that it's an array of instructions. Then that might hold true.
    So function[1] would return the 2nd instruction in the function and so on.
    But the C standard doesn't mandate any such thing...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #52
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    I don't have much to add because of the broken standard.
    I think you should start hoping that the C++ standard isn't "broken" in a similar way.

  8. #53
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I should hope, but I don't have much confidence in that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 04:52 PM
  2. Replies: 4
    Last Post: 04-01-2003, 12:49 AM
  3. passing structs to functions?
    By Neildadon in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2002, 04:31 PM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  5. probs with structs and functions
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 05-08-2002, 11:52 PM

Tags for this Thread