Function pointer arguments



I have some questions about the behavior of the code below.

#include <stdio.h>

void test(void *v);

int main(void)
{
int i=1;
int j=2;
void (*fp)();

fp = test;
(*fp)(&i, j);
test(&i);

return 0;
}

void test(void *v)
{
printf("address is %p\n", v);

return;
}

I compiled the code using gcc -Wall -ansi -pedantic. No warnings or
errors were issued.

1. Why was no error issued for the extra argument when using the
function pointer? If I put an extra argument when calling "test" in
the following line, an error is given. Thats what I would expect.

2. What's the behavior when running the code with the extra argument?

3. The compiler kind of worried me when it didn't give any warnings.
Now I'm not sure how function pointers are handled. Do I need a cast
when I correct the bad line and use (*fp)(&i) in the code above?

.



Relevant Pages

  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)
  • problem in java swings
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • ToolTips in a View and TTN_NEEDTEXT
    ... extern int g_minWorkPeriod; ... void CDayView::CreateAllFonts ... void CDayView::DrawDayLog(CDC* pDC) ... BOOL CDayView::TimeToY ...
    (microsoft.public.vc.mfc)