PDA

View Full Version : What's wrong with this code...


Asher
03-12-2004, 04:41:10
Oracle insists this is a compiler defect...I insist they cannot code.

#include "stdio.h"

typedef struct inv_struct
{
char (*x)[2];
} inv_struct;

struct st_struct
{
char x[2];
} st_struct;

int main()
{
int temp = 0;

inv_struct *z_struct;

st_struct.x[0] = '1';
st_struct.x[1] = '\0';

printf("%s\n", st_struct.x);

sprintf(z_struct->x[0], "%s", st_struct.x);
printf("%s\n", z_struct->x[0]);

return 0;
}
Compiling this testcase with "cc t.c" will output:

$ cc t.c
$ ./a.out
1
Memory fault


And yes, I know what's wrong with it. The question is, are you smarter than a programmer for Oracle?

Sir Penguin
03-12-2004, 07:00:09
They're not allocating memory for z_struct.

SP

Gary
03-12-2004, 09:11:51
Stares on, impressed, not knowing if the answer is correct or not.

Funkodrom
03-12-2004, 09:18:58
Originally posted by Sir Penguin
They're not allocating memory for z_struct.

SP

Those morons.

MDA
03-12-2004, 14:32:29
Oracle sucks. Or our gov't Oracle people suck, more likely.

Our "activity time reporting" software is Oracle, it crashes often, and even when it works, its clunky, and often stops prompts you for crap that doesn't apply to the field you're working in, or it will ask for crap that you've already entered and can SEE IN THE FIELD!

Asher
03-12-2004, 14:35:25
Originally posted by Sir Penguin
They're not allocating memory for z_struct.

SP
Indeed.

You would think that a C programmer for Oracle would understand that you need to allocate the memory before you start calling it.

And they wondered why the results were either a segfault or random outputs...

Clearly the problem is the compiler, not their inherent stupidity.

Funkodrom
03-12-2004, 15:04:43
I wouldn't think a programmer for any company would be competent.

Sir Penguin
03-12-2004, 23:28:45
That's all well and good, but this is just retarded.

SP

Darkstar
04-12-2004, 03:02:24
Actually, its just a very basic code mistake. Happens about as often as people using '=' as when they meant to use '=='.

Sir Penguin
04-12-2004, 10:03:18
Yes, that's not what's retarded. What's retarded is blaming it on the compiler.

SP

Darkstar
04-12-2004, 10:25:56
Well, the compiler should have obviously allocated the space automagically, without being told. I mean, if Microsoft Basic can manage it, obviously any compiler should.

Asher
04-12-2004, 18:28:30
I finally got them to concede...

I told them repeatedly they did not initialize z_struct.

"But I did! I did! See!"
inv_struct *z_struct;

Ugh.

Nav
06-12-2004, 11:59:44
Any language that requires you to define a variable before using it is backwards, over-complicated and silly.

LoD
06-12-2004, 13:45:33
Yeah, Haskell rulez!

Darkstar
06-12-2004, 21:31:22
I prefer having to declare my own variables. Helps cut down on bugs due to variable name typos. ;)

Cumber
16-12-2004, 00:24:37
Any language that lets you get away with not specifying exactly what you want, but instead infers what you probably wanted is a F***ING PAIN IN THE ARSE, for all the times when you DON'T want to do what it thinks you want to do, and you have to figure out how to trick it into doing what you were trying to tell it to do.

Also the bug thing DS mentioned. :)