Thread: A function which doesn't function

  1. #1
    Registered User
    Join Date
    Jun 2004

    A function which doesn't function

    I have started to write a program which will manage the queue of a clinic. The program is quit big, so I'm sending only the problematic core I'm facing now, which is ~80 lines longÖ Please bare with me a minute.
    The thing is when Iím running it, InsertPatient function is slipping away & doesnít come up to user interface.
    #include <stdio.h>
    #include <malloc.h>
    struct PatientDetails {
    	char F_name[15];
    	char L_name[20];
    typedef struct PatientDetails Patient;
    Patient CurrentPatient;
    struct LinkedList
    	Patient Data;
    	struct LinkedList *Next;
    typedef struct LinkedList Node;
    typedef Node *PtrToNode;
    Patient AbsrbPatient(Patient *PatientPtr)
    	puts ("\nPlease type patient's first name");
    	gets (PatientPtr->F_name);
    	printf ("\nfirst name is %s", PatientPtr->F_name); 
    	puts ("\nPlease type patient's last name");
    	gets (PatientPtr->L_name);
    	printf ("\nlast name is %s", PatientPtr->L_name);
    	return *PatientPtr;
    PtrToNode InitList()
    	PtrToNode P;
    	P = (PtrToNode) malloc(sizeof(Node));
    	if (P == NULL)
    		 puts ("Out of memory!");
    	P->Next = NULL;
    	return P;
    void InsertPatient(PtrToNode PatientPtr, PtrToNode list)
    	PtrToNode TmpCell;
    	if (TmpCell == NULL)
    		 printf("Out of memory!\n");
    	     list->Data = PatientPtr->Data;
    	     if (PatientPtr == NULL) 
    		TmpCell->Next = TmpCell;
    		PatientPtr = TmpCell;
    		TmpCell->Next = PatientPtr;
    		PatientPtr = TmpCell;
    int main(void)
    	Patient *PatientPtr = &CurrentPatient;
    	PtrToNode UrgentList, RegularList;
    	InsertPatient(PatientPtr, UrgentList);
    return 1;

    Debugger shows:
    warning C4133: 'function' : incompatible types - from 'struct PatientDetails *' to 'struct LinkedList *'
    I cannot seem to find why it complains of incompatible types!?
    Please help me find it.

  2. #2

    These warnings are expected behavior. According to ANSI standards, variables of type int* are different from variables of type short*. And, although the compiler may be able to perform an implicit promotion/demotion among intergral types (char, short, int, long, etc.), pointers are not of integral type.

    To remove these warnings, use an appropriate cast to instruct the compiler to explicitly convert the value from its current data type to the desired.

    The only restriction on the size of the short given by the ANSI standard is that it NOT be longer than an integer. Code should be written with this in mind so that it will be portable.

    Compiling the following program will generate the discussed warning:
    void ShortFunc( short, short * );
    void Func( int, int * );
    int main() {
    	short sTest;
    	short *sPoint;
    	ShortFunc(sTest, sPoint);
    	Func(sTest, sPoint);		// Generates warning
    	Func(sTest, (int *)sPoint);	// Does not generate warning
    	return 0;
    So for example, let's disect your code. Firstly, there is a LinkedList and a Patient struct. PtrToNode is a pointer to a LinkedList, and Patient is a declaration of PatientDetails.

    Now InsertPatient() takes two parameters, both PtrToNode. Though, in main() you call InsertPatient() with the first parameter of Patient while it should be a PtrToNode variable.

    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    Registered User
    Join Date
    Jun 2004
    So how do I solve this? How do I do cast in this situation? Or do I have to call Patient type in this function?
    Last edited by ronenk; 12-01-2004 at 05:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
Website Security Test