Jump to content
  • Advertisement
Sign in to follow this  

extern array seg fault

This topic is 3215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This code compiles with no errors or warnings but when I run my one-line program I get a seg fault: Record.h

struct SubrecordType{
	unsigned int name;
	char desc[24];

extern const int numsubrectypes;
extern const SubrecordType * const subrecordtypes;



#include "Record.h"

const int numsubrectypes = 2;

extern const SubrecordType subrecordtypes[numsubrectypes] = {
	{ 0                        ,   "Unknown Subrecord" },
	{ *((unsigned int *)"NAME"),   "Object ID"         }

#include <stdio.h>
#include "Record.h"

int main()
    printf("%i", subrecordtypes[0].name);
    return 0;

However! Changing extern const SubrecordType * const subrecordtypes; to extern const SubrecordType subrecordtypes[]; seems to have fixed my problem and all is well. I don't understand this. I grew up thinking [] was just a preallocated *const, and basically synonymous. I wracked my brain for hours today breaking my program into pieces trying to find this problem. I'm looking for some insight. HOW are these different? And if they are fundamentally different types then why didn't my compiler (GCC on Windows) even warn me about it? [Edited by - likeafox on February 25, 2010 11:36:02 AM]

Share this post

Link to post
Share on other sites
int [] x; means that x is an array of integers.
int * y; means that y is a pointer to an array of integers.

The compiler will automatically convert when you use an array where you need a pointer. This means y=x is a valid statement, even though the types differ.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!