在'setjmp'之后我是否必须调用'longjmp'

时间:2017-12-23 20:47:20

标签: c setjmp

longjmpsetjmp的联机帮助页中,有这一行:

  

如果调用setjmp()的函数在longjmp()之前返回   这个行为是未定义的。

这是否意味着我实际上必须在调用longjmp的函数或嵌套函数中的某处调用setjmp?或者根本不打电话可以吗?

1 个答案:

答案 0 :(得分:11)

你读错了。

  

如果在调用longjmp()之前调用setjmp()的函数返回,则行为未定义。

如果您在设置I solved this issue , even i was facing same issue , If you dont use local model you will not face issue or if you define your model in controller you will not face the issue. sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel" ], function(Controller,JSONModel) { "use strict"; return Controller.extend("SmartPurchaseReq.controller.Home", { /** * Called when a controller is instantiated and its View controls (if available) are already created. * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization. * @memberOf SmartPurchaseReq.view.Home */ onInit: function() { var that = this; var data = { "TileCollection" : [ { "icon" : "sap-icon://hint", "type" : "Monitor", "title" : "Tiles: a modern UI design pattern for overview & navigation." }, { "icon" : "sap-icon://inbox", "number" : "89", "title" : "Approve Leave Requests", "info" : "Overdue", "infoState" : "Error" }, { "type" : "Create", "title" : "Create Leave Requests", "info" : "28 Days Left", "infoState" : "Success" }, { "icon" : "sap-icon://travel-expense-report", "number" : "281", "numberUnit" : "euro", "title" : "Travel Reimbursement", "info" : "1 day ago" }, { "icon" : "sap-icon://loan", "number" : "2380", "numberUnit" : "euro", "title" : "My Salary", "info" : "8 days ago" }, { "icon" : "sap-icon:`enter code here`//lab", "number" : "1", "numberUnit" : "Invention", "title" : "Test Lab Reports", "info" : "8 Days Ago" }, { "icon" : "sap-icon://inbox", "type" : "Monitor", "title" : "Leave Request History" }, { "type" : "Create", "title" : "Create Purchase Order", "info" : "890€ Open Budget", "infoState" : "Success" }, { "icon" : "sap-icon://stethoscope", "number" : "3", "title" : "Yearly Health Check", "info" : "3 year overdue", "infoState" : "Error" }, { "icon" : "sap-icon://meal", "type" : "Monitor", "title" : "Meal Schedule" } ] }; var DummyModel = new JSONModel(); DummyModel.setData(data); // var sPath = jQuery.sap.getModulePath("model", "/Dummy.json"); // var DummyModel = new JSONModel(sPath); that.getView().byId("container").setModel(DummyModel); }, OnTilePress: function(evt) { var idj = evt.getSource(); var d =5; } /** * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered * (NOT before the first rendering! onInit() is used for that one!). * @memberOf SmartPurchaseReq.view.Home */ // onBeforeRendering: function() { // // }, /** * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here. * This hook is the same one that SAPUI5 controls get after being rendered. * @memberOf SmartPurchaseReq.view.Home */ // onAfterRendering: function() { // // }, /** * Called when the Controller is destroyed. Use this one to free resources and finalize activities. * @memberOf SmartPurchaseReq.view.Home */ // onExit: function() { // // } }); }); 的函数返回后调用,则longjmp的行为未定义。但完全可以来调用setjmp

Wikipedia更清楚:

  

如果调用setjmp的函数返回,则不再可能安全地将longjmp与相应的jmp_buf对象一起使用。

     

这是因为函数返回时堆栈帧无效。调用longjmp会恢复堆栈指针,因为返回的函数会指向不存在且可能被覆盖或损坏的堆栈帧。

这些函数通常用于处理异常机制。如果没有发生异常,您不想拨打longjmp,因为没有理由“回滚”您的程序。