⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.cc

📁 这是一个在linux平台上进行内存共享的例子
💻 CC
字号:
/*  example.cc  Show extended tclsh usage  Modification history:  */#include <stdio.h>#include <signal.h>#include "tcl.h"#ifdef HAVE_TCL_EXTEND#include "tclExtend.h"#endif#include "tk.h"#include "mbuff.h"       /*share memory head file*/// ident tag#ifndef __GNUC__#ifndef __attribute__#define __attribute__(x)#endif#endifstatic char __attribute__ ((unused)) ident[] =  "$Id: scncsh.cc,v 1.23 2001/09/27 18:10:42 paul_c Exp $";#ifdef SUN/*  The following variable is a special hack that is needed in order for  Sun shared libraries to be used for Tcl. */extern "C" int matherr ();int *tclDummyMathPtr = (int *) matherr;#endifstatic int * pcount;static inttalk_world(){	(*pcount)++;	return 0;}/* extende function */inttalk_to_world (ClientData clientdata,		  Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[]){  if (objc != 1)    {      Tcl_SetResult (interp, "you neednot talk too much!", TCL_VOLATILE);      return TCL_ERROR;    }   talk_world();  return TCL_OK;}intTcl_AppInit (Tcl_Interp * interp){  /*   * Call the init procedures for included packages.  Each call should   * look like this:   *   * if (Mod_Init(interp) == TCL_ERROR) {   *     return TCL_ERROR;   * }   *   * where "Mod" is the name of the module.   */  if (Tcl_Init (interp) == TCL_ERROR)    {      return TCL_ERROR;    }#ifdef HAVE_TCL_EXTEND  if (Tclx_Init (interp) == TCL_ERROR)    {      return TCL_ERROR;    }#endif  if (Tk_Init (interp) == TCL_ERROR)    {      return TCL_ERROR;    }  /*   * Call Tcl_CreateCommand for application-specific commands, if   * they weren't already created by the init procedures called above.   */  Tcl_CreateObjCommand (interp, "talk_to_world", talk_to_world,			(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);   return TCL_OK;}/*signal to quit */static voidthisQuit (ClientData data) {  if (pcount != 0)	mbuff_free("world", pcount);  Tcl_Exit(0);  exit(0);}static voidsigQuit (int sig){  thisQuit ((ClientData) 0);}intmain (int argc, char *argv[]){  /*create share mem using mbuff_alloc*/  pcount = (int *) mbuff_alloc("world", sizeof(int));  if (pcount == NULL)	exit(0);     // attach our quit function to exit  Tcl_CreateExitHandler (thisQuit, (ClientData) 0);  // attach our quit function to SIGINT  signal (SIGINT, sigQuit);  //  TclX_Main(argc, argv, Tcl_AppInit);  Tk_Main (argc, argv, Tcl_AppInit);/* release share memory using mbuff_free*/  mbuff_free("world", pcount);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -