1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "json.h"
// Is string on stack or data segment?
// UNTESTED ILLUSTRATION
int main(int argc, char* argv[]) {
// Array 'input_stack' (including the characters within it) is on the stack.
char input_stack[] = "[1,[2,\"three\"]]";
// Address input_data_segment refers to a location in the data segment where the
// characters are stored.
char* input_data_segment = "[1,[2,\"three\"]]";
// The argument to parse_json(…) is the address of a location in the data segment
// where the characters are stored.
ParseResult result = parse_json("[1,[2,\"three\"]]"); // argument is on data segment
// Although we passed a string literal, the compiler will convert that to the address
// in the data segment where those characters will be stored when the program runs.
if(result.is_success) {
free_element(result.element);
}
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 expandtab : */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.