有没有办法反转宏的顺序?

时间:2020-05-20 07:17:02

标签: c macros

你好(如果我在标题上有误,我事先表示歉意,

我正在编写一个程序,所有的事情,我创建了一个宏,但我想以相反的顺序使用它,例如:

class background_login extends AsyncTask<String, Void,String>
{

    AlertDialog dialog;
    Context context;
    public background_login (Context context)
    {
        this.context = context;
    }


    @Override
    protected void onPreExecute() {
        dialog = new AlertDialog.Builder(context).create();
        dialog.setTitle("Login Status");

    }

    @Override
    protected void onPostExecute(String s) {
        dialog.setMessage(s);
        dialog.show();



    }

    @Override
    protected String doInBackground(String... params)
    {
        String results="";
        String user_name = params[0];
        String password = params[1];

        String connstr= "url";

        try
        {
            URL url= new URL(connstr);
            HttpURLConnection http =(HttpURLConnection) url.openConnection();
            http.setRequestMethod("POST");
            http.setDoInput(true);
            http.setDoOutput(true);

            OutputStream ops = http.getOutputStream();
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ops,"UTF-8" ));
            String data = URLEncoder.encode("user_name","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")
                    +"&&"+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");

            writer.write(data);
            writer.flush();
            writer.close();
            ops.close();


            InputStream ips = http.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(ips, "ISO-8859-1"));
            String line ="";
            while ((line = reader.readLine()) !=null)
            {
                results+=line;
            }

            reader.close();
            ips.close();
            http.disconnect();
            return results;






        } catch (MalformedURLException e) {
            results= e.getMessage();
        } catch (IOException e) {
            results=e.getMessage();
        }


        return results;
    }
}

会变成类似这样的东西:

#define MAGIC "\x34\x19\x23\x4C"

有没有办法做到这一点,或者我需要写一个新书?

谢谢。

1 个答案:

答案 0 :(得分:0)

预处理器负责宏(因此在执行程序之前先对它们进行解释)。

如果您想在代码中同时使用"\x34\x19\x23\x4C""\x4C\x23\x19\x34",则最好声明一个静态全局变量,然后通过简单的反向函数对其进行修改。或者,实际上,声明两个宏。