I don't really understand what Visual Studio 2019 wants from me (C language). On one hand it doesn't throw me either error or warning, but on the other hand it marks me with a green squiggling the createCustomer
decaration in my API file. I would like to encapsulate Customer and use ADT on Customer structure.
These are my source and header files:
customer.h
#include <stdlib.h>
typedef struct Customer
{
unsigned int customerId;
const char* name;
int numOrders;
}Customer, * CustomerPtr;
customer.c
#include "customer.h"
#define MAX_NO_OF_CUSTOMERS 10
static Customer objectPool[MAX_NO_OF_CUSTOMERS];
static unsigned int customersCount = 0;
CustomerPtr createCustomer(const char* name, size_t numOrders)
{
CustomerPtr newCustomer_p = NULL;
if(customersCount < MAX_NO_OF_CUSTOMERS)
{
newCustomer_p = objectPool + (customersCount++);
newCustomer_p->name = name;
newCustomer_p->numOrders = numOrders;
}
}
customer_api.h
#include "customer.h"
CustomerPtr createCustomer(const char* name, int numOrders);
main.c
#include <stdio.h>
#include "main.h"
#include "customer_api.h"
int main()
{
CustomerPtr customer_p = createCustomer("Demo", 5);
return 0;
}
So as I said, under customer_api.h
the following CustomerPtr createCustomer(const char* name, int numOrders);
has squiggle under the function declaration createCustomer
. The program compiles and run successfully without errors/warnings.
Maybe I'm not using correctly the API h file concept? I'm trying to keep the customer properties implementation hidden from external files, so in other files I just include customer_api.h
anytime I need to approach the customer module.