•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 455,964 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,630 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1765 | Replies: 3 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Also argument 2 makes integer from a pointer with a cast. One argument is a struct declared in an included library. It's declared like:
the second argument is an unsigned int 2D array. It's used in a function to store hex numbers. It's declared like:
The reason I cast the struct variables to int is because they start as hex numbers. Can you see the problem from the code here?
struct pixelst *lzwArr; lzwArr = (struct pixelst *) malloc(pixels); // pixels is an int
the second argument is an unsigned int 2D array. It's used in a function to store hex numbers. It's declared like:
int dlzwHeight = (int)lzwArr[0].height; //cast to int
int dlzwWidth = (int)lzwArr[0].width; //cast to int
unsigned int dlzwArr[ dlzwHeight ][ dlzwWidth ];
dlzwFun(lzwArr, dlzwArr); //line giving the errorThe reason I cast the struct variables to int is because they start as hex numbers. Can you see the problem from the code here?
> The reason I cast the struct variables to int is because they start as hex numbers
This makes no sense at all.
What does this do?
The fact that the constant was written in hex, or was read from a string in hex and converted to an int doesn't make a bean of difference.
> unsigned int dlzwArr[ dlzwHeight ][ dlzwWidth ];
You appear to be trying to declare a variable sized array. If your compiler allows this (at all), it is non-standard behaviour.
> lzwArr = (struct pixelst *) malloc(pixels);
1. You cast the result of malloc. There is no need to do this if your C program is correct, and it hides problems if your C program is wrong.
2. The form should be
This makes no sense at all.
What does this do?
int a = 10; int b = 0xa; printf( "%d %d\n", a, b );
> unsigned int dlzwArr[ dlzwHeight ][ dlzwWidth ];
You appear to be trying to declare a variable sized array. If your compiler allows this (at all), it is non-standard behaviour.
> lzwArr = (struct pixelst *) malloc(pixels);
1. You cast the result of malloc. There is no need to do this if your C program is correct, and it hides problems if your C program is wrong.
2. The form should be
lzwArr = malloc ( pixels * sizeof *lzwArr );
I'm guessing you allocated a hell of a lot less than you though you had, and have been trashing lots of memory as a result. ![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- asp .net & vb .net html rich text editor (ASP.NET)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Help with Map (C++)
- a real challenge this time (C++)
- Type casting (C++)
- new and malloc (C++)
- Is it possible to have a template as an argument to a function? (C)
- Help me understand Pointers (C++)
- c language problm, how to pass pointer to a function (C)
- Text data type troubles in T-SQL (Database Design)
Other Threads in the C Forum
- Previous Thread: Need some help please
- Next Thread: Mysql Transaction API for C



Linear Mode