// Standard C++ <cstdarg> header
// Copyright (C) Florian Negele

// This file is part of the Eigen Compiler Suite.

// The ECS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The ECS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of the GNU General Public License version 3,
// the copyright holder grants you additional permissions to use
// this file as described in the ECS Runtime Support Exception.

// You should have received a copy of the GNU General Public License
// and a copy of the ECS Runtime Support Exception along with
// the ECS.  If not, see <https://www.gnu.org/licenses/>.

#ifndef ECS_CPP_CSTDARG_HEADER_INCLUDED
#define ECS_CPP_CSTDARG_HEADER_INCLUDED

#if defined __code__ || defined __avr__
	#define _va_pad(size) (size)
#else
	#define _va_pad(size) ((size) < sizeof (void*) ? sizeof (void*) : (size))
#endif

#define va_arg(ap, type) (*reinterpret_cast<type*> (((ap) += _va_pad (sizeof (type))) - _va_pad (sizeof (type))))
#define va_copy(dest, src) (void ((dest) = (src)))
#define va_end(ap) (void ((ap) = nullptr))
#define va_start(ap, par) (void ((ap) = reinterpret_cast<char*> (&(par)) + _va_pad (sizeof (par))))

namespace std
{
	using va_list = char*;
}

#endif // ECS_CPP_CSTDARG_HEADER_INCLUDED
