473,385 Members | 2,004 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,385 software developers and data experts.

function pointers

63
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  static int my_function(int a)
  4.  {
  5.      printf("my_function: %d\n", a);
  6.      return (2*a + 3);
  7.  }
  8.  
  9.  int main(void)
  10.  {
  11.      int (*new_function)(int) = my_function;
  12.      int  x;
  13.  
  14.      x = (*new_function)(10);
  15.      printf("main: %d\n", x);
  16.      return 0;
  17.  }
  18.  
i couldnt compile the above program
wats the error
Feb 20 '08 #1
6 1003
sicarie
4,677 Expert Mod 4TB
i couldnt compile the above program
wats the error
Umm, wouldn't your complier tell you the error?

Or is this a game and we're supposed to guess why?
Feb 20 '08 #2
askcq
63
Umm, wouldn't your complier tell you the error?

Or is this a game and we're supposed to guess why?
no ..i couldnt get where is the error
guide me
Feb 20 '08 #3
sicarie
4,677 Expert Mod 4TB
no ..i couldnt get where is the error
guide me
You said it did not compile. How do you know that? Depending on the compiler, you will either get an error on the console, in a pop-up, or in a status window.

Did you look for these? What compiler are you using?
Feb 20 '08 #4
There is nothing wrong with it!
Sometimes a newline is required at the end of your program.
All i can suggest is for you to put in a new line at the end of the file, that is press return to add an extra line. if this does not work i dont know because all i did is copy and paste then added the new line and it worked perfect.
Feb 21 '08 #5
manjuks
72
Hi,

Which compiler you are using? In gcc it works fine.

Thanks,
Manjunath
Feb 21 '08 #6
askcq
63
iam using miracle C compiler ...it was availble from net...
it says"parse error"
Feb 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
3
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
12
by: Bill Pursell | last post by:
The following code generates a compiler warning when compiled with gcc -pedantic: typedef (*FUNC)(int); FUNC f; void * get_f(void) { return &f;
57
by: Robert Seacord | last post by:
i am trying to print the address of a function without getting a compiler warning (i am compiling with gcc with alot of flags). if i try this: printf("%p", f); i get: warning: format %p...
54
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
32
by: copx | last post by:
Why doesn't the C standard include generic function pointers? I use function pointers a lot and the lack of generic ones is not so cool. There is a common compiler extension (supported by GCC...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.