Issues and questions about queues

This is a discussion on Issues and questions about queues within the C Programming forums, part of the General Programming Boards category; Originally Posted by Nazgulled But why do I need to access directly to the end of the queue? I will ...

  1. #31
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Nazgulled View Post
    But why do I need to access directly to the end of the queue? I will only have one element the end and the next pointer will be pointing to null, why would I need only this last element to use a method like his instead of the trivial q->next->next->next... that I'm used to?
    Suppose you have one million nodes in your list. Do you really want to go q->next->next->next->next->next->next->next->next->next->(omit hundreds of thousands of ->next)->next->next->next->next to get to the end?

    Yeah, that sounds "fast."

    Why would I need to access the last element?
    If you don't need to access it why the heck did you store it?

  2. #32
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    So, you are saying to use that first code example with a temporary variable and make the queue argument const right? Ok, I get it, just a simple question. You say that if something tries to change the memory to a const variable, the compiler will output an error. Will it compile nevertheless? Should I just ignore that error? Will the user running my application see any error outputting on the screen or it's perfectly safe to do it?

  3. #33
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by Nazgulled View Post
    So, you are saying to use that first code example with a temporary variable and make the queue argument const right? Ok, I get it, just a simple question.
    Yes, that's what any "sane" programmer would do At least those around here

    You say that if something tries to change the memory to a const variable, the compiler will output an error.
    Yes.

    Will it compile nevertheless?
    No.

    Should I just ignore that error?
    No.

    Will the user running my application see any error outputting on the screen or it's perfectly safe to do it?
    The user won't see anything since it won't compile.
    Const is there to pretty you from mistakes, among other things.
    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.

  4. #34
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    I know it probably doesn't matter if the keyword is there in the final binary but it could help in future versions so I don't mess it up right? Though, I just want to know if that means that if I use const through the coding and reach a final state in my application and if the application compiles without errors I can simply ignore the const keyword and remove it, correct?

  5. #35
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by Nazgulled View Post
    I know it probably doesn't matter if the keyword is there in the final binary but it could help in future versions so I don't mess it up right?
    That's kinda the idea. Or one of them anyway.

    Though, I just want to know if that means that if I use const through the coding and reach a final state in my application and if the application compiles without errors I can simply ignore the const keyword and remove it, correct?
    No, const is not something you remove at will. You should always write const where applicable. If you write your code correctly, then const will not hinder your program's functionality.
    If the const gets in the way, then you need to rethink your design.
    Don't remove const unless you put it there in error (for example, you put const on a variable that you need a function to modify or you use const on a function that sets data).
    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.

  6. #36
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    Ok, got it.

    Thanks very much for all the help you provided. Thanks to everyone else too, all of you have been very helpful.

  7. #37
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Programming is like an art. Don't forget this. You spend hours alone on thinking how you want to design and lay out your application code.
    In the end, the result is the same to the user, but you YOU, the programmer, it's something different entirely. Const is part of your design. Structs are part of your design, functions are part of your design, and so on.
    You just need to know how to lay out it properly and change it into something that works - and that is an art. Const is part of the art.

    And just for reference, let me state, the design, the art, is never visible to the end user. They know thing how about how much complexity is involved in your program that seems so simple.
    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.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Questions
    By John_L in forum Tech Board
    Replies: 11
    Last Post: 10-07-2008, 06:35 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  4. Interview questions
    By Stony in forum Tech Board
    Replies: 0
    Last Post: 11-11-2002, 07:10 PM
  5. Borland command line compiler issues.
    By NinePin in forum C Programming
    Replies: 5
    Last Post: 09-05-2002, 05:44 PM

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