Ok i tried putting in mutexs for the code but I don't think i get it still.
I put a mutex called lock in the LL struct.
long listSearch(listNodePtr listPtr, long key) {
listNodePtr ...
Type: Posts; User: seal308
Ok i tried putting in mutexs for the code but I don't think i get it still.
I put a mutex called lock in the LL struct.
long listSearch(listNodePtr listPtr, long key) {
listNodePtr ...
Nvm i think i figured it out.
While doing the return the value can change.
Hello
My teacher gave me sample code of a linked list thats not thread safe and told me to use pthreads mutex to make it thread safe
Sample code:
// routine to return the data from the node...
Thanks, this was a great help: Initialization Lists in C++ - Cprogramming.com
I'm new to c++.
Here's the constructor I'm trying to understand:
RealNum::RealNum(float initR) : r(initR) {}
I don't understand the part that's : r(initR)
What does it mean?
Nvm i figured it out.
"Class" should go in the header file and the not cpp file.
I am having trouble making a structure where Queue is a child of QueueItem, I get a "expected class name" error.
I'm doing this in xCode.
I have 4 files:
Queue.cpp, Queue.h,...
Ok, thank you.
Hello,
I usually only use typedefs for structs
eg) typdef struct STACK Stack;
So I don't have to keep writing struct STACK everywhere.
But I'm wonder what this typedef means:
typedef int...
Hello,
I am supposed to implement memory regions like this:
https://en.wikipedia.org/wiki/Region-based_memory_management
We are using a table that store the memory region name and a pointer to...
ok, will do, thanks for the advice.
Ok thank you.
That seems to have worked.
I just had the table.c and table.h file include the lifecycle.h file.
eg
#ifndef _TABLE_H
#define _TABLE_H
#include "lifecycle.h"
...
Actually I forgot to mention I'm supposed to use the header file given for lifecycle.h and not change it.
In that header file I have
#ifndef _LIFECYCLE_H
#define _LIFECYCLE_H
typedef...
By guards do you mean this?:
#ifndef _TABLE_H
#define _TABLE_H
#ifndef _LIFECYCLE_H
Hello,
I have 3 c files and 2 header files:
main.c, lifecycle.c, table.c, lifecycle.h and table.h
I worked on the table in a different problem with a different main and it works fine.
The...
Thank you, this worked perfectly.
I also had to made an change in the while token loop.
while (token)
{
...
token = strtok(NULL, delims);
}
Hello,
I am trying to tokenize an input txt file by spaces.
My code for it is:
while ( fgets (input, LENGTH, inputTxt))
{
token = strtok(input, " ");
Ok thank you.
I went through it with the lldb debugger and everything is clear now.
Because the node the newNode will point to has already been previously created I don't need to create new memory...
Hello,
I have 2 structs
struct CELL{
int row;
int column;
};
typedef struct CELL Cell;
Ok thank you.
Hello,
In my program I would like to assert that the size of my array is what I told it to be as a precondition for a function.
The function is:
void getRow(char *token, char *input)
{
...
Ok thx.
So then for any pointer in a struct I need to allocate memory for?
So if my struct contained a int* pointer.
Would the int it's pointing at need to be allocated as well?
so...
This is sample code written by my teacher.
He said you have to cast the return of malloc because malloc returns a void pointer.
You're probably right, but maybe we just haven't got to that point....
struct STRING
{
int size;
char *theString;
};
typedef struct STRING String;
String * newString( char const * const init )
Thank you, I understand it perfectly now.
It clicked when you said that const applies to what is on its immediate left.
It's easier for me to first think of it as empty of const so:
void...