473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Re: Please Explain This behaviour...,

On Thu, 2008-09-04 at 23:50 -0700, Pranav wrote:
The Code is compiling without Error/Bug/Exception..,
What are the possibilities for this behaviour?
//************************************************** *************
#include<stdio.h>

typedef struct abc_ *abc;

static abc param;

abc fun(void)
{
float *a = NULL;
a = (float *)malloc(sizeof(float));
if (a) {
return ((abc)(a));
}
return NULL;
}

int main()
{
param = fun();
printf("test_bandwidth_alloc: %x\n", param);
free(param);
}
ITYM


#include <stdio.h>
#include <stdlib.h /* Required for malloc() and free() */

typedef struct abc_ *abc;

static abc param;

abc fun(void)
{
/* Don't cast malloc, don't give types to sizeof */
float *a = malloc(sizeof *a);
if(a)
return (abc) a; /* Cleaned up, this is very suspicious.. */
return NULL;
}

int main(void)
{
param = fun();
/* You used %x, which you can't pass a pointer to. Use %p instead: */
printf("test_bandwidth_alloc: %p\n", (void *) param);
free(param);
}

--
Andrew Poelstra <ap*******@wpsoftware.com>
To email me, change .net to .com in the above address.
I just realized my reader isn't hiding my real address...

Sep 5 '08 #1
0 969

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Michael Strorm | last post by:
Hi! I posted a message a while back asking for project suggestions, and decided to go with the idea of creating an adventure game (although it was never intended to be a 'proper' game, rather an...
2
by: Abhish | last post by:
HI All ,:) I am a VC++ programmer,and some time My <b>Acumen</b> ask Microsofts VC++ (Visual Studio VC++ 6.0 )complier to complile my <b>senseless programs </b> ! :) <i><b> See what I have...
12
by: Sanjeev | last post by:
Output of followin program at Turbo C++ 3.0 is 7 ( Not 2 or 3). Please explain why ? //////////////////////////////////////////////// #include<stdio.h> #include<string.h> void main() {
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
22
by: Jaspreet | last post by:
I was recently asked this question in an interview. Unfortunately I was not able to answer it and the interviewer made a decision on my C strengths (or weekness) based on this single question and...
3
by: Aarti | last post by:
Hi, Can some one please explain why the output of this program is 15 #include <iostream> using namespace std; class A {
3
by: sathishc58 | last post by:
Hi All, Here is the code which generates Segmentation Fault. Can anyone explain why the third printf fails and the first printf works? main() { char ch={"Hello"}; char *p; ...
12
by: raghukumar | last post by:
# include <iostream> class A { public: A() : i(1) {} int i; } ; class B: public A { public :
2
by: sathishc58 | last post by:
Hi All Please explain why strlen returns() "16" as output here and explain the o/p for sizeof() as well main() { char a={'a','b','c'}; printf("strlen=%d\n", strlen(a));...
11
by: Pranav | last post by:
The Code is compiling without Error/Bug/Exception.., What are the possibilities for this behaviour? //*************************************************************** #include<stdio.h> typedef...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.