473,799 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

My program does NOT compile please help

3 New Member
hello,

I have to do the program for the bounded buffer problem in UNIX C and what I have so far is the following code

Expand|Select|Wrap|Line Numbers
  1. #include"genSema.h"
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include<pthread.h>
  5. #include<sys/types.h>
  6. #include<sys/times.h>
  7. #include<unistd.h>
  8.  
  9. int itCount=100;
  10. int N;
  11. int P_RAND_SEED = 1234;
  12. int C_RAND_SEED = 1234;
  13. #define FALSE 0;
  14. #define TRUE 1;
  15. int runFlag = TRUE;
  16. gen_semaphore *full;
  17. gen_semaphore *empty;
  18. void *producer(void *wp);
  19. void *consumer(void *wp);
  20.  
  21. struct buffer_t{
  22.        int buffer[10];
  23.        unsigned int nextFull;
  24.        unsigned int nextEmpty;
  25.  
  26. }widgets;
  27.  
  28. void* producer(void *wp)
  29. {
  30.        char *message1;
  31.        message1 = (char *)wp;
  32.        printf("%s ", message1);
  33.        int runFlag = TRUE;
  34.        int timeToProduce=100000;
  35.        int itCount;
  36.        struct buffer_t *widgPtr;
  37.        widgPtr = (struct buffer_t *)wp;
  38.        srand(P_RAND_SEED);
  39.        itCount=100;
  40.        while(runFlag) {
  41.              usleep(rand()%timeToProduce);
  42.              P(empty);
  43.              if((widgPtr->nextEmpty + 1)%N == widgPtr->nextFull)
  44.                continue;
  45.              widgPtr->buffer[widgPtr->nextEmpty] = itCount++;
  46.              widgPtr->nextEmpty = (widgPtr->nextEmpty+1) % N;
  47.              V(full);
  48.        }
  49.       printf("Producer: Terminating\\n");  
  50. }
  51.  
  52. void* consumer(void *wp)
  53. {
  54.        char *message2;
  55.        message2 = (char *)wp;
  56.        printf("%s ", message2);
  57.        int itCount;
  58.        int timeToConsume=100000;
  59.        struct buffer_t *widgPtr;
  60.        widgPtr = (struct buffer_t *) wp;       
  61.        srand(C_RAND_SEED);
  62.        int runFlag = TRUE;
  63.        while(runFlag) {
  64.           P(full);
  65.           itCount = widgPtr->buffer[widgPtr->nextFull];
  66.           widgPtr->nextFull = (widgPtr->nextFull+1) % N;
  67.           usleep(rand()%timeToConsume);
  68.           V(empty);
  69.       }
  70.      printf("Consumer: Terminating\n");
  71. }
  72.  
  73. main()
  74. {
  75.        int runTime = 2;
  76.        int i;
  77.        pthread_t prod_thrd;
  78.        pthread_t cons_thrd;
  79.        char *message1 = "producer running";
  80.        char *message2 = "consumer running";
  81.        empty = create_gen_semaphore(N);
  82.        full = create_gen_semaphore(0);
  83.        widgets.nextEmpty = 0;
  84.        widgets.nextFull = 0;
  85.        for(i = 0; i < N; i++)
  86.           widgets.buffer[i] = empty;
  87.        pthread_create(&prod_thrd, NULL, producer, message1);
  88.        printf("consumer created at main");
  89.        pthread_create(&cons_thrd, NULL, consumer, message2);
  90.        printf("producer created at main");
  91.        sleep(runTime);
  92.        runFlag = FALSE;
  93.        delete_gen_semaphore(empty);
  94.        delete_gen_semaphore(full);
  95.        printf("Main thread: Terminated\\n");
  96.        exit(1);
  97. }
now, the error I'm getting when compiling the code is the following:


Expand|Select|Wrap|Line Numbers
  1. $ gcc -o prodcons prodcons.c
  2. prodcons.c: In function `main':
  3. prodcons.c:86: warning: assignment makes integer from pointer without a 
  4. cast
  5. Undefined                       first referenced
  6.  symbol                             in file
  7. P                                   /var/tmp//cc6O6sjK.o
  8. V                                   /var/tmp//cc6O6sjK.o
  9. create_gen_semaphore                /var/tmp//cc6O6sjK.o
  10. delete_gen_semaphore                /var/tmp//cc6O6sjK.o
  11. ld: fatal: Symbol referencing errors. No output written to prodcons
  12. collect2: ld returned 1 exit status

Please does anyone know what is that mean and why I'm getting this error. Another this that I would like to let you know about is that in the explanation for the code they tell you that "your job is to define all the italicized functions for thread management and syncronization. "

of course the italicized functions are (create_gen_sema phore, delete_gen_sema phore, P, V)
Oct 25 '08 #1
3 1721
Banfa
9,065 Recognized Expert Moderator Expert
The first error is on line 86, have you examined that line? Could you describe what you think it is doing?

The other errors are because you have not implemented the functions that you are supposed to implement for you assignment.

And finally what is the purpose of your variable N, it is used in many places but never has a value assigned to it.
Oct 25 '08 #2
Nanoooo
3 New Member
well I have looked at the error and that is why I'm asking here because I dont know what is the problem with line 86!!!

The other thing is that I dont know what do you mean about my functions? like I didnt declare them? or what? and I dont know what to assign for N to be honest...
Oct 25 '08 #3
Banfa
9,065 Recognized Expert Moderator Expert
well I have looked at the error and that is why I'm asking here because I dont know what is the problem with line 86!!!
What were you trying to do with that piece of code?

The other thing is that I dont know what do you mean about my functions? like I didnt declare them? or what? and I dont know what to assign for N to be honest...
No it looks like you declared them but it looks like they are not defined anywhere.

Your program is not going to work if you don't assign something to N. It sounds like you are trying to write your program without having a good idea of what it is meant to be doing.
Oct 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
14170
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
5
5327
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of these files, I wish to do the same using another python code instead of running each of these files one by one, which would be cumbersome giving the argv of each file every single time. This can be easily done using a shell script but I just...
5
2839
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
14
1799
by: Peter Williams | last post by:
Hi All, I am attempting to reverse-obsfuscate an IOCCC entry, and my ultimate goal is to convert the code into Delphi (OO Pascal). I don't understand what the question-mark (?) operator, and the percent (%) operator does. How do I translate this line (obviously declaring some integers) into pascal ???
3
5268
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error (0xc0000005 at address 535F072A): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are...
3
1599
by: wongjoekmeu | last post by:
Hiya all, I have a strange problem. I have compiled a program with g++ compiler. It seems to compile fine. I can even compile it with debug (-g) option. However at the very beginning when I run the program I get a segmentation fault. "Program receive SIGSEGV signal." is what I see when I use a debugger. I have even put a print state right in the beginning of the main() function. It seems that the program does not reach this state at all....
14
3224
namcintosh
by: namcintosh | last post by:
Hello, everyone. Well, let me cut to the chase and explain my problem. I am trying to devise a menu plan that uses the if/else if and the while loop. The program calculates the user's weight on a given planet. It first asks for the user's weight, asks them for a choice. If they choose choices 1 though 9, the user's weight will be calculated on whatever choice they picked (for example, if the user inputs 150 as their weight and choose...
4
4056
by: Billy | last post by:
Hi! I'm using: -Compiler: Borland Command Line C++ Compiler 5.5.1 -Code Editor: SciTE 1.75 Anybody know how we can in Scite with command Tools|Go (F5) compile and run my c or cpp program at the same time? So I won't first compile and then run, but all in one step.
87
3757
by: pereges | last post by:
I have a C program which I created on Windows machine. I have compiled and executed the program on windows machine and it gives me the consistent output every time i run it. for eg. input a = 2, b =3 lets say a sum operation is to be performed, then: output: 5
3
2613
by: kr151080 | last post by:
I need some help with a Measurement Program I Wrote.....I have this code as the main workings of my program: import java.util.*; public class Measurement{ { static Scanner console = new Scanner(System.in) public static void main(String args); double feet, inches, feetTotal, inchTotal, centTotal; boolean done;
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.