Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


#pragma function( function1 [, function2, ...] )

Specifies that calls to functions specified in the pragma's argument list be generated. If you use the intrinsic pragma (or /Oi) to tell the compiler to generate intrinsic functions (intrinsic functions are generated as inline code, not as function calls), you can use the function pragma to explicitly force a function call. Once a function pragma is seen, it takes effect at the first function definition containing a specified intrinsic function. The effect continues to the end of the source file or to the appearance of an intrinsic pragma specifying the same intrinsic function. The function pragma can be used only outside of a function — at the global level.

For lists of the functions that have intrinsic forms, see #pragma intrinsic.


// pragma_directive_function.cpp
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// use intrinsic forms of memset and strlen
#pragma intrinsic(memset, strlen)

 * Find first word break in string, and set remaining
 * chars in string to specified char value.
char *set_str_after_word(char *string, char ch)
  int i;
  int len = strlen(string);  /* NOTE: uses intrinsic for strlen */

  for(i = 0; i < len; i++) {
    if (isspace(*(string + i))) 

  for(; i < len; i++) 
    *(string + i) = ch;
  return string;

// do not use strlen intrinsic
#pragma function(strlen)

 * Set all chars in string to specified char value.
char *set_str(char *string, char ch)
  /* NOTE: uses intrinsic for memset, but calls strlen library function */
  return (char *) memset(string, ch, strlen(string));

int main(void)
  char *str = (char *) malloc(20 * sizeof(char));

  strcpy(str, "Now is the time");
  printf("str is '%s'\n", set_str_after_word(str, '*'));
  printf("str is '%s'\n", set_str(str, '!'));

  return 0;


str is 'Now************'
str is '!!!!!!!!!!!!!!!'

See Also

Pragma Directives

© 2016 Microsoft