Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:34:31+00:00 2026-06-13T08:34:31+00:00

I’m in the process of creating a simple 2D game engine in C with

  • 0

I’m in the process of creating a simple 2D game engine in C with a group of friends at school. I’d like to write this engine in an Object-Oriented way, using structs as classes, function pointers as methods, etc. To emulate standard OOP syntax, I created a create() function which allocates space in memory for the object. I’m in the process of testing it out, and I’m receiving an error. Here is my code for two files that I’m using to test:

test.c:

#include <stdio.h>

int main()
{
        typedef struct
        {
                int i;
        } Class;

        Class *test = (Class*) create(Class);
        test->i = 1;

        printf("The value of \"test\" is: %i\n", test->i);

        return 0;
}

utils.c:

#include <stdio.h>
#include <stdlib.h>
#include "utils.h"

void* create(const void* class)
{
        void *obj = (void*) malloc(sizeof(class));
        if (obj == 0)
        {
                printf("Error allocating memory.\n");
                return (int*) -1;
        }
        else {
                return obj;
        }
}

void destroy(void* object)
{
        free(object);
}

The utils.h file simply holds prototypes for the create() and destroy() functions.

When I execute gcc test.c utils.c -o test, I’m receiving this error message:

test.c: In function 'main':
test.c:10:32: error: expected expression before 'Class'

I know it has something to do with my typedef at the beginning, and how I’m probably not using proper syntax. But I have no idea what that proper syntax is. Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:34:32+00:00Added an answer on June 13, 2026 at 8:34 am

    Your code make no sense in this area

    Class *test = (Class*) create(Class);
    

    Class is a type name. Why are you trying to pass it as an argument to create? You cannot use type names as a function arguments in C.

    Your create function seems to expect some sort of pointer as an argument. The purpose of that pointer is entirely unclear to me, but the bottom line here is that type name Class cannot be used as an argument here.

    Inside your create you use sizeof(class) as the amount of memory to allocate. This sizeof(class) will simply evaluate to a pointer size, which is absolutely not what you need.

    Basically, you need to rethink what you are trying to do and do it from scratch. I’d suggest reading so book on C first. What you have now is just… random.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.