首页 \ 问答 \ __attribute __((constructor))的工作原理如何?(How exactly does __attribute__((constructor)) work?)

__attribute __((constructor))的工作原理如何?(How exactly does __attribute__((constructor)) work?)

似乎很清楚,它应该设置好了。

  1. 什么时候运行?
  2. 为什么有两个括号?
  3. __attribute__是一个函数吗? 一个宏? 句法?
  4. 这是否在C工作? C ++?
  5. 它的功能是否需要静态?
  6. __attribute__((destructor))何时运行?

目标C示例 :

__attribute__((constructor))
static void initialize_navigationBarImages() {
  navigationBarImages = [[NSMutableDictionary alloc] init];
}

__attribute__((destructor))
static void destroy_navigationBarImages() {
  [navigationBarImages release];
}

It seems pretty clear that it is supposed to set things up.

  1. When exactly does it run?
  2. Why are there two parentheses?
  3. Is __attribute__ a function? A macro? Syntax?
  4. Does this work in C? C++?
  5. Does the function it works with need to be static?
  6. When does __attribute__((destructor)) run?

Example in Objective-C:

__attribute__((constructor))
static void initialize_navigationBarImages() {
  navigationBarImages = [[NSMutableDictionary alloc] init];
}

__attribute__((destructor))
static void destroy_navigationBarImages() {
  [navigationBarImages release];
}

原文:https://stackoverflow.com/questions/2053029
更新时间:2023-10-10 21:10

最满意答案

不同的变量名!

$ReviewID = $_POST['reviewiduser']; //without final s
foreach($ReviewIDs as $ReviewID) {  //with final s.
/*               ^    */

编辑:你说你还有问题。 可能你的$ _POST是一个字符串。 尝试:

$reviewIDs = json_decode($_POST['reviewiduser']);

这可能会使$ reviewID成为与foreach一起工作的正确数组。


I was posting from Java to Php as a string and treating it in php like it was an array.

In Java I was posting selectOwnUserReviews which was of the format like "[1,34,78]". It looked like an array but was all treated as one unit. And even if I tried operations in php I was doing it on [1 and 34 and 78], not on 1 and 34 and 78.

So in Java I did:

//convert [56,23,87] to a string
selectOwnUserReviews = Arrays.toString(category.getUserReviewIds());
//remove [ and ] so we have a string of 56,23,87
selectOwnUserReviews = selectOwnUserReviews.substring(1,selectOwnUserReviews.length()-1);

Now I have the string 56,23,87 and I post this string to my php. In my php I use explode to get the individual values, my complete code looking like:

<?php
    require('file.php');

    $ReviewID = $_POST['reviewiduser'];

    $ReviewID = explode(",",$ReviewID);

    $results = array();

    foreach($ReviewID as $ReviewID) {
        $sql2 = "SELECT * FROM review WHERE review_id = ?";
        $stmt2 = $con->prepare($sql2) or die(mysqli_error($con));
        $stmt2->bind_param('i', $ReviewID) or die ("MySQLi-stmt binding failed ".$stmt2->error);
        $stmt2->execute() or die ("MySQLi-stmt execute failed ".$stmt2->error);
        $result2 = $stmt2->get_result();

        while($row = mysqli_fetch_array($result2)) {//make an array called $results
            $results[] = array(
                'category' => $row['cat_name'],
                'name' => $row['name'],
                'phone' => $row['phone'],
                'comment' => $row['comment'],
                'reviewid' => $row['review_id'],
            );
        }
    }

        echo json_encode($results);

?>

Job done.

相关问答

更多
  • 不同的变量名! $ReviewID = $_POST['reviewiduser']; //without final s foreach($ReviewIDs as $ReviewID) { //with final s. /* ^ */ 编辑:你说你还有问题。 可能你的$ _POST是一个字符串。 尝试: $reviewIDs = json_decode($_POST['reviewiduser']); 这可能会使$ reviewID成为与foreach一起工作的 ...
  • 感谢@NguyenQuangAnh,我意识到我没有指定ApplicationController是应用程序类。 我也查看了这个页面http://rominirani.com/android-application-class/ ,我在那里学到了更多。 基本上:更新了android清单
    我找到了解决方案。 我需要在AndroidManifest.xml中添加“android:name =”utils.AppController“”行。
    我没有传递一些参数,这是APi强制要求的参数,因此我得到了期望失败的错误。 I was not passing some parameters, which were mandatory for the APi's to call, therefore i was getting the expectation failed error.
  • 在您的路线中,您定义了一个 Route::get 这意味着此路由正在侦听GET方法。 在您的控制器中指定 $method = $request->method(); if($method == 'POST') { 这意味着你的控制器实际上只返回你有POST的东西,因为你的路由调用你的控制器只听GET 您可以完全删除方法的检查。 只有在将路径映射到控制器方法时,才能调用控制器方法。 如果你还想支持POST,只需添加即可 Route::post( ... ) 一点提示: 在您的应用中使用它们之前,尝试使用 ...
  • 是的你可以。 JSON被添加到POST请求的主体中,如下所示: JSONObject jsonObject; // your JSON here requestQueue.add(new JsonObjectRequest(Method.POST, url, jsonObject, listener, errorListener); Yes you can. The JSON is added to the body of a POST request, like this: JSONObject jso ...
  • 您的设备上是否启用了互联网? 您是否在清单中设置了INTERNET权限? 编辑: 检查您的网址是否正确。 The problem was due to the fact that the request I was sending was empty. I thought that Volley would convert it to the correct JSON representation({}) by itself. Instead, I think the request was just a ...
  • 所以你得到错误的原因是因为 "latitude": { "index1": "100", "index2": "200", } 应该( 为了让你的代码工作 ): "latitude": [ { "index1": "100" }, { "index2": "200" }, ] 在原始的JSON中,您刚刚获得了一个名为index1和index2的JSON对象。 在第二个JSON中,您有一个JSON对象数组,其中index1作为第一个元素中的键,而i ...
  • 好吧,显然解决方案非常简单,只需要深入挖掘文档:) http://laravel.com/docs/requests 特别是这个注意: 一些JavaScript库(如Backbone)可以将输入作为JSON发送到应用程序。 您可以通过Input :: get正常访问此数据。 Well, apparently the solution is very simple, just needed to dig deeper into documentation :) http://laravel.com/docs/ ...
  • 如何将适配器与Volley合并? 首先,我认为您需要修复您的URL,然后您只需添加到像Arraylist这样的适配器 第二,你的ArrayAdapter的第二个参数需要是一个包含android:id/text1的ID的布局,如果你不打算提供任何额外的参数(没关系,你不知道它,它埋在文档中) 。 话虽这么说,单个TextView有一个内置的布局 //Get the listview ListView listView = (ListView) findViewById(R.id.mobile ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。