Sponsored Content
Top Forums Programming Implementing a stack of strings in C Post 302707501 by afulldevnull on Friday 28th of September 2012 06:33:51 PM
Old 09-28-2012
Implementing a stack of strings in C

I'm trying to create a simplified version of dc to learn from. The first thing I notice is that the main stack stores strings. How would I implement a string stack in C? How is something like this:

Code:
struct StringStack
{
   const unsigned int pysicalSize;     // physical size of the stack
   const char ** const basePtr;        // cannot change bottommost pointer or pointee
   char **stackPtr;                    // top of stack
   unsigned int logicalSize;           // number of elements in the array
};

Thoughts?

---------- Post updated at 06:33 PM ---------- Previous update was at 04:59 PM ----------

Actually I don't think I need the stackPtr because I can just use the basePtr + the logicalSize.
 

8 More Discussions You Might Find Interesting

1. Programming

Implementing a shell in C

Hi, I am implementing a shell in C, with the following problem... Suppose the shell is invoked from the command line as >> myshell < test.in > test.out 2>&1 I have to execute the commands in test.in and redirect them to test.out How does one detect in the main function that the shell... (1 Reply)
Discussion started by: jacques83
1 Replies

2. Programming

what is stack winding and stack unwinding

helo can u tell me what do you mean by stack winding and stack unwinding Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

3. Programming

Implementing the TCP stack

Hello, I am trying to implement TCP protocol in C. I have read the RFC for TCP and have knowledge about it. But I am stuck in coding. Are ther any reference links, code snippets available for reference? (1 Reply)
Discussion started by: Harsh
1 Replies

4. Shell Programming and Scripting

Implementing Password

I am trying to implement a login screen to the following code how would i go about doing so. I have try to place the password in a variable using if statements which would usually work but as i have the system in a while loop i think i need to find another method. #!/bin/bash #Filename:... (4 Replies)
Discussion started by: warlock129
4 Replies

5. Shell Programming and Scripting

Help with implementing logging

I'm trying to add logging to an existing script which echos a number of lines to the screen. I've added a switch to the script that is going to suppress much of this output and put it in a file instead. The way I envisioned it was like this: $log would be set to either "" or the log files... (8 Replies)
Discussion started by: cheetobandito
8 Replies

6. Shell Programming and Scripting

Need help in implementing logic

i have following input file... 00290002STDR000000000000000000000000000EOD END TRANSACTION ^@^@^@^@^@^@^@^@^@^@^@^@^ 00299998STDR070000000007000000000000000STANDING DEBITS ^@^@^@^@^@^@^@^@^@^@^@^@^... (1 Reply)
Discussion started by: sagarrd
1 Replies

7. Shell Programming and Scripting

Need help in implementing expect

Hello All, I am trying a shell script for automatically login to test servers and pulling the output of top command from all using expect. ----snippet of code --- #!/usr/bin/expect -f #!/bin/bash server1=10.251.222.51 server=("$server1") i=1 for exp_server in ${server}; do expect -c... (3 Replies)
Discussion started by: Renjesh
3 Replies

8. UNIX for Dummies Questions & Answers

Kernel Stack vs User Mode Stack

Hi, I am new to the linux kernel development area. I want to know what is the difference between kernel mode stack and user mode stack? Does each process has a user mode stack and a kernel mode stack?? Or Each process has a user mode stack and there is only one kernel mode stack that is shared by... (4 Replies)
Discussion started by: saurabhkoar
4 Replies
STACK(9)						   BSD Kernel Developer's Manual						  STACK(9)

NAME
STACK -- stack macros SYNOPSIS
#include <sys/param.h> type STACK_ALLOC(sp, size); type STACK_MAX(sp, size); type STACK_ALIGN(sp, bytes); type STACK_GROW(sp, size); type STACK_SHRINK(sp, size); DESCRIPTION
A stack is an area of memory with a fixed origin but with a variable size. A stack pointer points to the most recently referenced location on the stack. Initially, when the stack has a size of zero, the stack pointer points to the origin of the stack. When data items are added to the stack, the stack pointer moves away from the origin. The STACK_ALLOC() macro returns a pointer to allocated stack space of some size. Given the returned pointer sp and size, STACK_MAX() returns the maximum stack address of the allocated stack space. The STACK_ALIGN() macro can be used to align the stack pointer sp by the specified amount of bytes. Two basic operations are common to all stacks: a data item is added (``push'') to the location pointed by sp or a data item is removed (``pop'') from the stack. The stack pointer must be subsequently adjusted by the size of the data item. The STACK_GROW() and STACK_SHRINK() macros adjust the stack pointer sp by given size. A stack may grow either up or down. The described macros take this into account by using the __MACHINE_STACK_GROWS_UP preprocessor define. SEE ALSO
param(3), queue(3) BSD
April 8, 2011 BSD
All times are GMT -4. The time now is 10:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy