My little stack library - what do you think?

This is a discussion on My little stack library - what do you think? within the C Programming forums, part of the General Programming Boards category; I made this library just for fun. It works perfectly. There is a C version with a structure named "STACK" ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163

    My little stack library - what do you think?

    I made this library just for fun. It works perfectly. There is a C version with a structure named "STACK" and a C++ version with a class named "STACK". You can push anything onto the stack (including raw data) and than pop it back later. There is also an "empty" command to clear the stack. It was developed in DevCpp.

    Please no flaming, I just want your comments.

    Download
    Code:
    Table of contents
    
    BIN--------|
    |          DLL------|
    |          |        C----|
    |          |        |   libstackc.a
    |          |        |   stackc.dll
    |          |        |
    |          |        C++--|
    |          |            libstackcpp.a
    |          |            stackcpp.dll
    |          STATIC---|
    |          |       libstackc.a
    |          |       libstackcpp.a
    |         stack.h
    |         stack.hpp
    |
    EXAMPLE----|
    |         stackexample.c
    |         stackexample.cpp
    |
    SRC--------|
               C----|
               |    dll-----|
               |    |      Stack Library.dev
               |    |      stack.c
               |    |      stack.h
               |    |
               |    static--|
               |           Stack Library.dev
               |           stack.c
               |           stack.h
               |
               |
               C++--|
                    dll-----|
                    |      Stack Library.dev
                    |      stack.cpp
                    |      stack.hpp
                    |
                    static--|
                           Stack Library.dev
                           stack.cpp
                           stack.hpp

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    My main question would be "why?" - at least in C++, stack would typically be best implemented as a template, which would make it a .h only implementation.

    --
    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
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by matsp View Post
    My main question would be "why?" - at least in C++, stack would typically be best implemented as a template, which would make it a .h only implementation.

    --
    Mats
    Why not, rather? The best exercise to learn is to code. Almost everything you can possibly due within a reasonable time-frame in your own home as a hobby has been done before. It's all about the learning experience.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    I think it is painfully obvious that you're not a C++ dev, hauzer. The C++ implementation leaves a little to be desired.
    And I would like to comment that you should not strip the names of the parameters from function prototypes.

    I'm sorry, but seeing as you use C-style functions and methods, I think you better scrap the C++ version and focus on your C version or learn C++ a little better before you attempt.
    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. #5
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Well, as IceDane said, I wrote it only to exercise myself, specificly in the pointer&memory area of C because I'm a little thin there. Maybe someone will find it as a good example, I don't know.

    EDIT:
    @Elysia: yeah, I know. I really didn't experiment with C++ features much, maybe it's time.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    I see... then I can suggest that you learn new/delete, templates, possible smart pointers and vectors. It would probably make a much better class.
    Oh and usually C++ devs use T* instead of T * because it's strictly typed. Just a thought, no need to change.
    Good luck anyway.
    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. #7
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Thanks everyone.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack Implementation and Exceptions
    By audinue in forum C Programming
    Replies: 4
    Last Post: 06-22-2008, 09:32 AM
  2. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM
  3. Stack
    By planet_abhi in forum C Programming
    Replies: 2
    Last Post: 04-12-2003, 04:22 AM
  4. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 10:13 AM
  5. inputting line of text vs. integers in STACK
    By sballew in forum C Programming
    Replies: 17
    Last Post: 11-27-2001, 10:23 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