Click here to Skip to main content
15,887,289 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: freeing pointers in pointer array causes SegFault Pin
Jordanwb28-Feb-11 6:57
Jordanwb28-Feb-11 6:57 
QuestionMAPI: MapiRecipDesc is not properly working with Lotus Notes (ver8.5) [modified] Pin
vinvino200122-Feb-11 2:55
vinvino200122-Feb-11 2:55 
AnswerRe: MAPI: MapiRecipDesc is not properly working with Lotus Notes (ver8.5) Pin
vinvino200123-Feb-11 20:17
vinvino200123-Feb-11 20:17 
QuestionFunction pointer syntax help Pin
Xpnctoc19-Feb-11 17:38
Xpnctoc19-Feb-11 17:38 
AnswerRe: Function pointer syntax help Pin
Alain Rist19-Feb-11 20:19
Alain Rist19-Feb-11 20:19 
GeneralRe: Function pointer syntax help Pin
Xpnctoc20-Feb-11 10:15
Xpnctoc20-Feb-11 10:15 
AnswerRe: Function pointer syntax help Pin
Yusuf20-Feb-11 1:45
Yusuf20-Feb-11 1:45 
AnswerSOLVED: Re: Function pointer syntax help Pin
Xpnctoc20-Feb-11 10:29
Xpnctoc20-Feb-11 10:29 
I found the problem. I only posted a limited version of the code to focus the direction of the inquiry. In the context of the full code, what is going on is that the compiler expects all variables to be declared at the beginning of the function.

Original code:
#include <stdio.h>

typedef void (*VoidFunctionPtr)(void);

void FunctionA(void)
{
    printf("You are in Function A.\n");
}

int main(void)
{
    printf("Here is a program that does something.\n");
    VoidFunctionPtr fp = FunctionA; // FAILS because variables must be declared first.
    fp();
}

Revised code:
#include <stdio.h>

typedef void (*VoidFunctionPtr)(void);

void FunctionA(void)
{
    printf("You are in Function A.\n");
}

int main(void)
{
    VoidFunctionPtr fp = FunctionA; // MOVED variable declaration to first line.

    printf("Here is a program that does something.\n");
    fp();
}

I'm sure this wouldn't happen in a C++ project, but I am using compiler settings to force Standard C compilation. I come from a C++ background but I'm trying to learn the differences between C++ and standard C. I bought a book on standard C, but it references the "C99" standard, which apparently allows variables to be defined anywhere in a function. I guess the MS C compiler works on an older standard?
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Albert Holguin20-Feb-11 11:26
professionalAlbert Holguin20-Feb-11 11:26 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Xpnctoc20-Feb-11 12:36
Xpnctoc20-Feb-11 12:36 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Michael Dunn20-Feb-11 21:43
sitebuilderMichael Dunn20-Feb-11 21:43 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Xpnctoc21-Feb-11 4:15
Xpnctoc21-Feb-11 4:15 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Albert Holguin21-Feb-11 10:51
professionalAlbert Holguin21-Feb-11 10:51 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Xpnctoc21-Feb-11 10:56
Xpnctoc21-Feb-11 10:56 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Albert Holguin21-Feb-11 10:56
professionalAlbert Holguin21-Feb-11 10:56 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Xpnctoc21-Feb-11 10:59
Xpnctoc21-Feb-11 10:59 
GeneralRe: SOLVED: Re: Function pointer syntax help Pin
Albert Holguin21-Feb-11 15:18
professionalAlbert Holguin21-Feb-11 15:18 
QuestionANSI C in VS 2010 Pin
Xpnctoc16-Feb-11 3:50
Xpnctoc16-Feb-11 3:50 
AnswerRe: ANSI C in VS 2010 Pin
Xpnctoc16-Feb-11 4:02
Xpnctoc16-Feb-11 4:02 
GeneralRe: ANSI C in VS 2010 Pin
Richard MacCutchan16-Feb-11 4:12
mveRichard MacCutchan16-Feb-11 4:12 
GeneralRe: ANSI C in VS 2010 Pin
Xpnctoc16-Feb-11 11:46
Xpnctoc16-Feb-11 11:46 
GeneralRe: ANSI C in VS 2010 Pin
Richard MacCutchan16-Feb-11 21:35
mveRichard MacCutchan16-Feb-11 21:35 
GeneralRe: ANSI C in VS 2010 Pin
Albert Holguin20-Feb-11 11:29
professionalAlbert Holguin20-Feb-11 11:29 
AnswerRe: ANSI C in VS 2010 Pin
Richard MacCutchan16-Feb-11 4:14
mveRichard MacCutchan16-Feb-11 4:14 
GeneralRe: ANSI C in VS 2010 Pin
Xpnctoc16-Feb-11 11:46
Xpnctoc16-Feb-11 11:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.